Skip to content

Skip decoding rule state without prefilter keys - #1023

Merged
matthyx merged 1 commit into
mainfrom
fix/prefilter-fastpath-20261007
Oct 8, 2026
Merged

matthyx merged 1 commit into
mainfrom
fix/prefilter-fastpath-20261007

Conversation

@matthyx

@matthyx matthyx commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Rules without prefilter keys currently marshal their state, decode it into rawParams, and discard the empty result on each refresh. Skip the decoding step for validated JSON whose top-level keys cannot match a prefilter field.

Keep merging, binding precedence, JSON validation, existing warning paths, and the invariant that nonnil Params has an active filter. Match encoding/json field lookup with strings.EqualFold, including Unicode cases such as portſ. json.Valid keeps decoder validation failures on the existing error path. No persistent cache is added: public rule state maps remain mutable, including through shallow result copies.

Validation:

  • Regression tests for unknown-value marshal validation, malformed recognized fields, all seven filter names and case variants, binding overrides, direct state mutation, and rule sync/update/delete/register behavior.
  • Baseline regression tests passed before production changes; public rule-manager/binding-cache race tests and vet pass. Independent architecture and code reviews approve.
  • Five samples per parser benchmark, same toolchain/dependencies: unknown-only state falls from 673 to 416 B/op and 9 to 7 allocations (~38% fewer bytes), with median time 854ns to 645ns (~24% faster). Nested unknown state uses ~36% fewer bytes. Nil state stays zero-allocation.
  • Recognized filters retain their allocations and incur roughly 6–9% more time per parse in these local benchmarks; initialized nonnil filters are subsequently reused by the creator.

The parser accounted for only ~0.6% of allocation bytes in the latest short production profile. This is a small local improvement, not a promise of a measurable whole-agent memory reduction. The direct DigitalOcean five-minute smoke/profile run completed with matched image configuration, process ages, and workload placement, with zero frontend failures, workload restarts, or detected export/drop errors. Whole-agent allocation was lower, but the change was dominated by unchanged code and cannot be attributed to this shortcut. Working set was 4.3% higher; the 116 additional goroutines were existing ants pool workers. Sparse parser samples do not establish a production allocation improvement or regression. The newer v0.3.254-based private integration was separately tested; it was not the graph profiled on DO.

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a75c32f6-16de-4568-900a-b3584bc4db0d
📥 Commits

Reviewing files that changed from the base of the PR and between e33c1ff and 0d25e4c.

📒 Files selected for processing (3)
  • pkg/rulemanager/prefilter/parse_state_test.go
  • pkg/rulemanager/prefilter/prefilter.go
  • pkg/rulemanager/rulecreator/factory_prefilter_state_test.go
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.168 0.170 +1.0%
Peak CPU (cores) 0.177 0.182 +3.0%
Peak CPU p95 (cores) 0.176 0.182 +3.4%
Avg Memory (MiB) 379.670 322.575 -15.0%
Peak Memory (MiB) 382.453 331.840 -13.2%
Dedup Effectiveness

No data available.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The optimization preserves existing behavior and is covered by focused regression tests.

0 open findings

What changed in this PR

Optimizes rule-state parsing by skipping unnecessary JSON decoding when no prefilter keys exist.

Changes:

  • Detects all case-insensitive prefilter keys before decoding.
  • Preserves JSON validation and mutable rule-state behavior.
  • Adds regression tests and parsing benchmarks.
File Description
pkg/​rulemanager/​prefilter/​prefilter.go Adds the decode fast path.
pkg/​rulemanager/​prefilter/​parse_state_test.go Tests validation, key matching, mutations, and benchmarks.
pkg/​rulemanager/​rulecreator/​factory_prefilter_state_test.go Tests rule lifecycle and shared-state behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@matthyx matthyx added the release Create release label Oct 7, 2026
@matthyx
matthyx merged commit 3a17bef into main Oct 8, 2026
40 checks passed
@matthyx
matthyx deleted the fix/prefilter-fastpath-20261007 branch October 8, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release Create release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants