Skip to content

Optimize name parsing#73

Merged
nikku merged 5 commits intomainfrom
opimize-name-parsing
Dec 4, 2025
Merged

Optimize name parsing#73
nikku merged 5 commits intomainfrom
opimize-name-parsing

Conversation

@nikku
Copy link
Owner

@nikku nikku commented Dec 4, 2025

Which issue does this PR address?

On top of #70, this PR provides incremental improvements to further speed up FEEL expression parsing. It ships three optimizations:

  • keys and prefixes for a context are tokenized and efficiently cached ➡️ matching of existing keys when parsing longer names becomes O(1)
  • key, prefixes and normalized keys are cached, so that normalizeContextKey is only called once per key ➡️ reduces calls to the function during test suite execution from 500.000 ❗ to 6.244
  • when setting a variable on a VariableContext we instantiate the new context directly, instead of doing expensive key traversal

As a result we see another round of significant speedups, around 33% according to my tests.

Existing tests verify this is a non-breaking change.

Before

image

Test execution time average around ~330ms, with spikes for large contexts.

After

image

Test execution time average around ~210ms, speedup of ~30%.


Closes #59, #67

@nikku nikku marked this pull request as draft December 4, 2025 08:07
Base automatically changed from simplify-context-merging to main December 4, 2025 08:55
@nikku nikku force-pushed the opimize-name-parsing branch 2 times, most recently from aa9f7eb to 55c04c2 Compare December 4, 2025 21:45
@nikku nikku changed the title Opimize name parsing Optimize name parsing Dec 4, 2025
@nikku nikku force-pushed the opimize-name-parsing branch 2 times, most recently from 855bb92 to 75067dd Compare December 4, 2025 22:00
@nikku nikku marked this pull request as ready for review December 4, 2025 22:01
nikku added 4 commits December 4, 2025 23:25
Compute context keys and prefixes only once to
prevent excessive re-parsing with larger context
sizes.

Because the cache is shared, it can in principle
be re-used across parses, further speeding up
consecutive parse operations.

Closes #59, #67
As a shortcut to prevent expensive computation we instantiate
a new `VariableContext` directly when setting a new key.
@nikku nikku force-pushed the opimize-name-parsing branch from 71d5ff3 to 492eb02 Compare December 4, 2025 22:25
@nikku nikku force-pushed the opimize-name-parsing branch from 492eb02 to 035a309 Compare December 4, 2025 22:29
@nikku nikku merged commit b0d5274 into main Dec 4, 2025
2 checks passed
@nikku nikku deleted the opimize-name-parsing branch December 4, 2025 22:30
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.

Language parsing becomes slow with large contexts

1 participant