feat: Add rulesForJSONEventNonBlocking with linear performance on large arrays#243
Closed
feat: Add rulesForJSONEventNonBlocking with linear performance on large arrays#243
Conversation
In moveFrom(), check nameState.getTransitionOn() before enqueuing an ACStep. Fields with no value transition from the current NameState would be immediately discarded by tryStep() anyway.
…ge arrays Add a new matching method that provides array-consistent matching with guaranteed linear performance regardless of array size. The existing rulesForJSONEvent can exhibit O(N^2) performance when events contain large arrays at paths matching multi-field rules. The new method avoids this by: 1. Using a field name index in Event to jump directly to relevant fields in ACFinder.moveFrom(), instead of iterating all remaining fields 2. Pre-checking ArrayMembership consistency before enqueuing steps 3. For events with object arrays, using StructuredFinder which walks the JSON tree and matches per-element (AC correct by construction) The new method is semantically equivalent to rulesForJSONEvent — same rules match same events. Validated against 679 existing tests + 51 new correctness cases covering flat, object-array, primitive-array, nested, mixed, and edge cases. Performance on events up to ~900KB: - Primitive arrays: ~100ms (linear) - Object arrays 20k elements: 77ms vs TIMEOUT on old method - Nested 2-level 2k outer x 10 inner: 50ms vs TIMEOUT on old method - Customer-like 6-field rule: ~46ms (linear)
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.
Issue #, if available:
Performance improvement for matching events with large arrays.
Description of changes:
Adds a new method
rulesForJSONEventNonBlocking()onGenericMachinethat provides array-consistent matching with guaranteed linear performance regardless of array size.The existing
rulesForJSONEvent()can exhibit O(N^2) performance when events contain large arrays at paths matching multi-field rules. For example, an event with a 10,000-element array matching a 2-field rule can take several seconds, while the new method completes in ~40ms.What changed:
ACFinder.moveFrom(): Instead of iterating all remaining fields, uses a field name index to jump directly to relevant fields, and pre-checks array membership consistency before enqueuing steps.Event.java: Builds a field name to index range map during construction (fields are already sorted by name, so same-name fields are contiguous).NameState.java: AddsgetValueTransitionKeys()to expose which field names a state transitions on.StructuredFinder.java(new): For events with object arrays, walks the JSON tree structurally and matches per-element. Array consistency is correct by construction since each match call only sees one element's fields.GenericMachine.java: AddsrulesForJSONEventNonBlocking()and deprecatesrulesForJSONEvent().Semantics: The new method is equivalent to
rulesForJSONEvent()— same rules match same events. Validated against all 679 existing tests plus 51 new correctness cases.Benchmark / Performance (for source code changes):
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.