Skip to content

Cap the parsed pattern cache at 1000 patterns - #92

Merged
borgar merged 2 commits into
borgar:masterfrom
HardMax71:fix/bound-pattern-cache
Oct 16, 2026
Merged

borgar merged 2 commits into
borgar:masterfrom
HardMax71:fix/bound-pattern-cache

Conversation

@HardMax71

Copy link
Copy Markdown
Contributor

Every valid pattern stays in the parsed-pattern cache for the life of the process, about 6 KB each, so formatting many distinct patterns grows the heap without limit (#91).

This caps the cache at 1000 patterns and drops the oldest one when it's full. A workbook uses a few dozen patterns, so normal use still parses each pattern once. Lookups are unchanged; the size check only runs when a new pattern is parsed.

Heap after 100,000 distinct patterns
master 8 MB -> 628 MB
this branch 8 MB -> 11 MB

test/pattern-cache.spec.ts checks that a pattern is cached and that the oldest one is dropped once the cache is full; the second test fails on master. npm run test, lint and typecheck pass. Happy to change the number or make it an option.

HardMax71 and others added 2 commits October 15, 2026 10:13
Every valid pattern stayed in the cache for the life of the process,
about 6 KB each, so formatting many distinct patterns grew the heap
without limit. Drop the oldest pattern once 1000 are cached.
@borgar
borgar merged commit 3d4cac9 into borgar:master Oct 16, 2026
3 checks passed
@borgar

borgar commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Very good catch, and an elegant solution. I've added an LRU cache in #94 which I'll hook in here to but I wanted the test so I've merged this first.

Release should be out over the weekend at the latest.

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.

2 participants