Repository navigation
perf(arith): single-static parse cache for CmpLT + PostInc - #922
Merged
Merged
Conversation
First knife: one thread-local ARITH_PARSE_CACHE (alongside ARITH_WRITES) holding at most one CmpLT and one PostInc specialization, so the for ((i=0;i<N;i++)) cond/update pair stays resident instead of thrashing a single slot. Key is (raw expr text, no_expand flag). Admission is a three-layer AND reusing arithmetic_preexpansion_is_identity + fast_arith_ticket_shape plus a new shape rejection (?: , / % ** && ||), fronted by a single-pass union-alphabet pre-filter so assignment traffic like x+=i short-circuits before the whitelist scans run. GNU expr.c has no parse cache (readtok + recursive descent per evalexp), so this is pure acceleration: a hit with a non-plain-decimal (or array/assoc/nameref/readonly/dynamic incl. RANDOM) load falls back to the slow parser without evicting, and the closures read live (no const fold). Change limited to src/executor/arithmetic/*; compound_exec.rs untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First arith-cache cut: per-slot CmpLT(i<N)/PostInc(i++) closures, key=(raw text,no_expand), triple-AND gate (identity + ticket shape + reject ?: , / % ** && ||) with union-alphabet prefilter. Miss on non-plain-decimal/dynamic/octal falls back without eviction. GNU expr.c has no such cache, pure speedup; semantics unchanged. Tests: lib 639 (incl 3 new) + cli green (examples fails are missing submodule in worktree only). Release N=200k: ~827->781ms (-5.5%), empty-loop ~821->774ms (-5.7%).