Repository navigation
Numfmt: TEXT() and chart labels parse each format code once (#806) - #808
Merged
h-a-n-a-s-h-i merged 2 commits intoOct 13, 2026
Merged
Conversation
…d#806) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts: # ROADMAP.md
Member
|
Merged — thank you @vangel76 for the contribution! I merged main into your branch to resolve conflicts with other PRs that landed first. |
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.
Fixes #806
What was redundant
text_functioncalledNumberFormat::parse(code)on every call, and the evaluator calls it once per element, so=TEXT(A1:A100000,"0.00")parsed the same code 100,000 times.chart/src/resolve.rsdid the same per resolved value, andFmt::newinchart/src/axis.rsper label helper call. A parsed format depends on the code text only (date system and value are applied when formatting), so one parse per distinct code is enough. No timings claimed.What changed
numfmt:NumberFormat::parse_cached(code), a per-thread cache (thread_local, no lock, no unsafe, no dependency, wasm-safe). At most 64 codes; a full cache is emptied. Codes over 256 bytes are never stored. If the cache is unavailable (thread shutdown, re-entrant borrow) it falls back to a plain parse; no unwrap/expect.text_function,chart/resolve.rsandchart/axis.rsuse it. The calc evaluator gets it throughtext_function.NumberFormat::parseis unchanged.Tests (
crates/numfmt/src/tests.rs)text_functionequals a copy of the old uncached implementation with the cache cold and warm, andformat_valuewithparse_cachedequalsformat_valuewithparse.Commands run
cargo test -p gridcraft-numfmt,cargo test -p gridcraft-calc -p gridcraft-functions -p gridcraft-chart,cargo test -p gridcraft-engine --lib display,cargo clippy -p gridcraft-numfmt -p gridcraft-chart --all-targets -- -D warnings,cargo fmton numfmt and chart,cargo xtask layers,cargo check -p gridcraft-numfmt --target wasm32-unknown-unknown.Left out
Mutex<HashMap>cache indisplay.rsis untouched (it holds the lock while parsing).&'static str; this one is keyed by user code. Possible textual conflict in thelib.rsimports only (mine adds a self-contained module and uses full paths).🤖 Generated with Claude Code