Skip to content

collections: cache data in FindAll() - #11

Open
blotus wants to merge 2 commits into
mainfrom
findall-reuse
Open

blotus wants to merge 2 commits into
mainfrom
findall-reuse

Conversation

@blotus

@blotus blotus commented Oct 2, 2026

Copy link
Copy Markdown
Member

tx.GetField() calls col.FindAll() for every rule × every variable it targets. Each call builds a
fresh []corazarules.MatchData + []types.MatchData holding every entry of the collection:

  • Map.FindAll / NamedCollectionNames.FindAll: two allocations of size n per call.
  • ConcatKeyed.FindAll / ConcatCollection.FindAll (ARGS = ARGS_GET + ARGS_POST, ARGS_NAMES, …):
    calls the children's FindAll, rewrites Variable_ on the results in place (replaceVariable),
    and grows the result with repeated append.

Within a phase the collections don't change, so this is the same copy rebuilt hundreds of times.
Cost is O(rules × args): with CRS, a 16KB JSON body (~600 ARGS) allocated ~20MB per request, and
madvise + memclr + GC were ~40–50% of CPU.

GetField also lowercases every match's key (strings.ToLower(c.Key())) even when the rule has no
exceptions, and compacts the slice in place.

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