Add MultiTagInsertionFilter #6184
Open
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.
A tiny performance / clarity improvement. There's just one major potential issue with the MeterFilter.commonTags(): as it accepts Iterable, there's no guarantee that end user won't provide List, Set or another implementation that is not Tags, and the downstream code would then create a new Tags instance on every call, resulting in the heavyweight sorting. This PR makes sure that the concatenated instance is always Tags, plus carries some negligible good manners, not recreating an object if nothing has changed and providing a meaningful class name in the stack traces. As with other PRs, we can get a much more significant speedup if we provide an interface to create Tags from already sorted collections (see #6113), as here we can do the same process as in Tags.merge(), preallocating array of a necessary size and doing O(n) iterative merge.
The benchmarks used were the ones in #6174, OpenJDK 21.0.2, Intel N100 at fixed 2GHz. They simulate the worst case, when user provides a list and not a Tags instance. How to read the table: injected = number of tags to be inserted by the filter, supplied = mode of the number of tags in incoming Meter.Id. Incoming Meter.Id may have 0-64 tags, with 90% probability this number equals exactly mode, in other 10% cases it is evenly distributed across other values in 0-64 range. It included some manual editing, so there might be (hopefully not) editing mistakes.
33.160 ± 0.229
3.049 ± 0.001
30.885 ± 0.066
3.065 ± 0.092
53.590 ± 0.069
3.067 ± 0.112
50.770 ± 0.085
3.044 ± 0.001
51.077 ± 0.089
3.041 ± 0.001
51.161 ± 0.092
3.085 ± 0.179
26.964 ± 0.087
3.042 ± 0.001
52.232 ± 0.189
3.060 ± 0.031
122.293 ± 0.154
49.965 ± 0.118
196.077 ± 0.258
115.836 ± 0.192
197.922 ± 0.432
131.757 ± 0.401
224.569 ± 0.327
138.881 ± 0.548
253.095 ± 0.295
179.739 ± 0.519
304.351 ± 0.397
228.875 ± 0.389
396.117 ± 2.037
316.573 ± 1.356
551.046 ± 1.552
487.610 ± 1.934
144.861 ± 0.220
65.845 ± 0.177
226.178 ± 0.334
135.478 ± 0.329
260.228 ± 0.213
161.769 ± 0.296
279.380 ± 0.307
193.212 ± 0.321
327.282 ± 0.557
241.633 ± 0.709
408.249 ± 0.545
318.136 ± 0.642
526.307 ± 0.554
441.163 ± 1.102
766.677 ± 1.308
658.538 ± 1.695
182.301 ± 0.245
77.630 ± 0.175
272.785 ± 0.396
161.470 ± 0.604
313.002 ± 0.439
195.466 ± 0.812
392.977 ± 1.067
265.163 ± 0.678
449.671 ± 0.706
346.768 ± 0.483
549.557 ± 0.671
439.445 ± 0.513
701.312 ± 0.647
593.615 ± 0.775
960.017 ± 1.318
857.253 ± 1.779
270.091 ± 0.372
98.874 ± 0.209
391.446 ± 0.758
209.299 ± 0.698
442.482 ± 0.558
277.086 ± 0.725
542.029 ± 0.635
369.562 ± 0.795
699.364 ± 1.231
489.296 ± 1.543
794.251 ± 0.965
626.974 ± 0.930
983.273 ± 0.920
804.285 ± 0.678
1254.053 ± 1.832
1066.830 ± 1.275
445.825 ± 0.904
129.738 ± 0.200
641.263 ± 0.649
289.152 ± 0.436
713.181 ± 0.690
372.448 ± 0.663
830.807 ± 0.499
487.805 ± 0.843
1004.185 ± 1.122
649.396 ± 0.764
1237.963 ± 1.436
895.591 ± 1.937
1487.600 ± 1.168
1145.585 ± 5.210
1756.124 ± 2.213
1396.981 ± 5.869
839.912 ± 0.733
165.206 ± 0.337
1103.111 ± 1.202
413.303 ± 0.512
1222.819 ± 1.091
530.356 ± 0.653
1364.309 ± 1.599
664.749 ± 0.785
1548.493 ± 1.255
865.435 ± 0.966
1851.388 ± 1.451
1159.547 ± 5.038
2253.046 ± 8.181
1534.134 ± 3.198
2362.974 ± 2.457
1705.116 ± 7.068
874.147 ± 1.409
166.424 ± 0.374
1270.810 ± 2.079
566.643 ± 0.696
1469.561 ± 2.525
742.514 ± 1.207
1666.623 ± 2.374
916.976 ± 1.348
1859.909 ± 2.711
1118.062 ± 1.540
2219.444 ± 2.526
1404.797 ± 2.394
2439.326 ± 3.140
1683.831 ± 7.463
1941.294 ± 2.460
1191.606 ± 1.200