-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently the flattener and more specifically "NameTracker" is not hierarchy aware, to explain that let's examine this case: Pattern: `{ "context": { "user_id": [1] } }` Event: `{ "context": { "user_id": 1 }, "payload": { /* lots of fields, large payload */ }` In this case the flattener will read context and then user_id, all the other values (strings, objects and arrays) will be skipped, but still will get traversed. By replacing the "NameTracker" with "SegmentsTreeTracker" which is aware of the hierarchy, we can: * Know that once we read "user_id" we can stop consuming the event and exit * Cache the paths - so `pathForChild` is not needed and we reduce allocations. ``` name old time/op new time/op delta CityLots-10 4.42µs ± 0% 4.28µs ± 0% ~ (p=1.000 n=1+1) _JsonFlattener_ContextFields-10 9.06µs ± 0% 0.21µs ± 0% ~ (p=1.000 n=1+1) _JsonFlattener_MiddleNestedField-10 10.9µs ± 0% 1.8µs ± 0% ~ (p=1.000 n=1+1) _JsonFlattener_LastField-10 9.65µs ± 0% 9.68µs ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_ContextFields-10 9.42µs ± 0% 0.50µs ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_MiddleNestedField-10 11.0µs ± 0% 2.0µs ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_LastField-10 9.81µs ± 0% 9.87µs ± 0% ~ (p=1.000 n=1+1) name old alloc/op new alloc/op delta CityLots-10 985B ± 0% 832B ± 0% ~ (p=1.000 n=1+1) _JsonFlattener_ContextFields-10 48.0B ± 0% 0.0B ~ (p=1.000 n=1+1) _JsonFlattener_MiddleNestedField-10 64.0B ± 0% 0.0B ~ (p=1.000 n=1+1) _JsonFlattener_LastField-10 32.0B ± 0% 0.0B ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_ContextFields-10 232B ± 0% 184B ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_MiddleNestedField-10 240B ± 0% 48B ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_LastField-10 80.0B ± 0% 48.0B ± 0% ~ (p=1.000 n=1+1) name old allocs/op new allocs/op delta CityLots-10 38.0 ± 0% 31.0 ± 0% ~ (p=1.000 n=1+1) _JsonFlattener_ContextFields-10 3.00 ± 0% 0.00 ~ (p=1.000 n=1+1) _JsonFlattener_MiddleNestedField-10 4.00 ± 0% 0.00 ~ (p=1.000 n=1+1) _JsonFlattener_LastField-10 2.00 ± 0% 0.00 ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_ContextFields-10 9.00 ± 0% 6.00 ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_MiddleNestedField-10 9.00 ± 0% 3.00 ± 0% ~ (p=1.000 n=1+1) _JsonFlattner_Evaluate_LastField-10 5.00 ± 0% 3.00 ± 0% ~ (p=1.000 n=1+1) ``` Signed-off-by: Yosi Attias <[email protected]>
- Loading branch information
Showing
23 changed files
with
511 additions
and
202 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.