Repository navigation
HermitCrab: cut FeatureStruct clone and VariableBindings allocation - #633
johnml1135 wants to merge 7 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #633 +/- ##
==========================================
+ Coverage 75.53% 75.65% +0.12%
==========================================
Files 455 455
Lines 38933 39022 +89
Branches 5428 5441 +13
==========================================
+ Hits 29407 29523 +116
+ Misses 8376 8355 -21
+ Partials 1150 1144 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…Bindings roll back lazily instead of cloning per call Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…al and restore tests plus comments on the scratch array and missing nested transactions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… contracts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tree path A node with more values than the remaining scratch slots now goes straight to the map copy, so a wide structure (over 31 values) costs what master's Clone did instead of about 1.5-1.8x. The check is one comparison per node; clones are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nstead of corrupting a transaction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ow on VariableBindings Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
e6852c4 to
e2912b1
Compare
|
Verdict: approve. The rebase onto master left the PR's code as it was, and e2912b1 rewords the Most important: F6, Counts: 0 Critical, 0 Important, 0 Low open. No new findings. What I ran: The compare from e6852c4 to e2912b1 reports Not verified: I was not permitted to run API/parity: Public F1 addressed · F2 addressed · F3 addressed · F4 withdrawn · F5 withdrawn, unverified · F6 addressed Reviewed at e2912b1 |
Part of #632
Start here:
FeatureStruct.Cloneand the per-callVariableBindingsclone are two of the largest allocation sources in HermitCrab parsing. This PR removes most of that traffic without changing semantics: Clone takes a map-free tree path for plain structures, and Unify/Subsumes/IsUnifiable snapshot the bindings lazily, only if something is written, and roll back on failure. Allocation falls 11-18% and paired wall time 4-19%, with identical parse output. Public API is unchanged.What changed
FeatureStruct.Clonefirst tries a recursive tree clone with nocopiesdictionary. A thread-static 32-slot array records visited values. If any value is reachable twice (reentrance, Forward chains, cycles) or the structure has more than 32 nodes, it falls back to the existing map-based copy, so reentrant semantics are unchanged.VariableBindingsgains internalBeginTransaction/EndTransaction. The three operations write in place; the bindings shallow-snapshot their dictionary on the first write and restore it on failure. Binding values are only read, never mutated, so the shallow snapshot is equivalent.VariableBindingsmust not be shared across threads. HermitCrab uses per-word bindings. Transactions do not nest; a nested call on the same thread does not own the rollback.Behaviour change: a
VariableBindingsused by two threads at once now throwsInvalidOperationException("VariableBindings is not safe for concurrent use") instead of risking silent corruption. No caller shares one.A/B (interleaved, alternating order, n=15 per workload, new process per sample, 1 warm + 2 timed passes, load average 8-13 on 20 cores)
perfwas unavailable, so CPU is getrusage child time (user+sys). It agrees in sign with wall everywhere.Verification
FeatureModel: 20 passed, 0 failed (Release, net10.0). Earlier filtered run over FeatureModel|FiniteState|Matching|Rules: 30 passed.FeatureStructCloneTests(13 tests):Clone()against the map-based copy for a plain tree, a reentrant structure, a Forward chain, a cycle, nesting at 10/16/17/40 levels, and a large reentrant structure, checking equality, sharing and reentrance. Failed Unify, IsUnifiable and Subsumes that wrote mid-operation leave the bindings unchanged. The rollback tests fail when the rollback is disabled.Risks: measured on a loaded machine (wall noise is real; Amharic and Mbugwe are solid at 15/15 and 13/15, Aweti is a mild win). Parse equality checked on 60/30/30 words, not the full lists.
Next: re-measure with
perfon a quiet machine before deciding on the larger copy-on-write rewrite; cheaper candidates are the remaining_definitedictionary per FeatureStruct and SymbolicFeatureValue flag clones.🤖 Generated with Claude Code
This change is