Skip to content

perf(arith): single-static parse cache for CmpLT + PostInc - #922

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/arith-parse-cache
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/arith-parse-cache

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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%).

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.
@caomengxuan666
caomengxuan666 merged commit 1e77f9f into master Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/arith-parse-cache branch October 20, 2026 15:34
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