Skip to content

nets.ml: speed up discrimination-net lookup#183

Open
aqjune-aws wants to merge 2 commits into
jrh13:masterfrom
aqjune-aws:map
Open

nets.ml: speed up discrimination-net lookup#183
aqjune-aws wants to merge 2 commits into
jrh13:masterfrom
aqjune-aws:map

Conversation

@aqjune-aws
Copy link
Copy Markdown
Contributor

Replace the single (term_label * 'a net) list of edges in each net node
with a record that splits children by label kind: a direct vnet field
for the catchall Vnet edge plus persistent Map.Make balanced trees for
Cnet/Lcnet (keyed by name+arity) and Lnet (keyed by arity).

This is an algorithmic improvement to discrimination-net lookup:

  • Vnet branch is O(1) instead of an O(n) scan over edges.
  • Other lookups are O(log n) per bucket via balanced trees.
  • Comparators are monomorphic (String.compare / int compare) so the
    speedup is visible in bytecode as well as native code.

The speedup of running times of a couple of s2n-bignum proofs is as follows:

  • x86/curve25519/bignum_inv_p25519: 9m 55s -> 7m 29s (30% faster)
  • x86/p256/p256_montjadd: 12m 22s -> 8m 49s (40% faster)

Also, at most 20% & in average 5% speedup is found from holtest.
This patch is purely written by Claude Code.

Also, this PR fixes holtest.mk's TacticTrace so that it doesn't have to rely on external HOLLIGHT_DIR setup.

aqjune-aws and others added 2 commits June 5, 2026 05:03
Replace the single (term_label * 'a net) list of edges in each net node
with a record that splits children by label kind: a direct vnet field
for the catchall Vnet edge plus persistent Map.Make balanced trees for
Cnet/Lcnet (keyed by name+arity) and Lnet (keyed by arity).

This is an algorithmic improvement to discrimination-net lookup:
- Vnet branch is O(1) instead of an O(n) scan over edges.
- Other lookups are O(log n) per bucket via balanced trees.
- Comparators are monomorphic (String.compare / int compare) so the
  speedup is visible in bytecode as well as native code.

Tips remain a sorted list because they are read in bulk (tryfind in
REWRITES_CONV) and typically very short.

Also annotate the head-classifier helpers (label_to_store /
label_for_lookup) and net_update / follow with explicit term_label
types so that grepping for term_label finds every place it flows.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@aqjune-aws
Copy link
Copy Markdown
Contributor Author

The CI check failures are resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant