replace Set<Integer> with BitSet for HTTP statuses#1496
Merged
Conversation
lpriima
approved these changes
May 27, 2020
Contributor
Author
|
Here's a quick demonstration of why we might want to avoid boxing on things like this (none of the times are large enough to care about): @State(Scope.Benchmark)
public class HashSetVsBitSet {
BitSet bitSet;
HashSet<Integer> hashSet;
@Param({"0", "500"})
int offset;
int[] codes;
@Setup(Level.Trial)
public void init() {
bitSet = new BitSet(offset + 100);
bitSet.set(offset, offset + 100);
hashSet = new HashSet<>();
for (int i = offset; i < offset + 100; ++i) {
hashSet.add(i);
}
codes = new int[] { offset, offset + 1, offset + 50, offset + 101};
}
@Benchmark
@OperationsPerInvocation(4)
public void hashSet(Blackhole bh) {
for (int code : codes) {
bh.consume(hashSet.contains(code));
}
}
@Benchmark
@OperationsPerInvocation(4)
public void bitSet(Blackhole bh) {
for (int code : codes) {
bh.consume(bitSet.get(code));
}
}
}Since we're dealing with HTTP statuses, we're outside the default range of the |
bantonsson
approved these changes
May 27, 2020
tylerbenson
approved these changes
May 27, 2020
Contributor
tylerbenson
left a comment
There was a problem hiding this comment.
Looks good to me. One optional suggestion.
| assert config.httpServerErrorStatuses == toBitSet(expected.toSet()) | ||
| assert config.httpClientErrorStatuses == toBitSet(expected.toSet()) | ||
| assert propConfig.httpServerErrorStatuses == toBitSet(expected.toSet()) | ||
| assert propConfig.httpClientErrorStatuses == toBitSet(expected.toSet()) |
Contributor
There was a problem hiding this comment.
Since these don't need to be sets anymore, consider removing the toSet() and updating toBitSet
…Dog/dd-trace-java into richardstartin/bitset-http-statuses
iNikem
pushed a commit
to open-telemetry/opentelemetry-java-instrumentation
that referenced
this pull request
Jun 2, 2020
* Add time in queue (DataDog/dd-trace-java#1481) * Minor upgrades (DataDog/dd-trace-java#1495) * Allow user to disable kafka time in queue tag (DataDog/dd-trace-java#1487) * Replace Set<Integer> with BitSet for HTTP statuses (DataDog/dd-trace-java#1496) * Register WeakMapProvider earlier in AgentInstaller (DataDog/dd-trace-java#1480) * Update codenarc (DataDog/dd-trace-java#1500) Co-authored-by: Tyler Benson <tyler.benson@datadoghq.com> Co-authored-by: Nikolay Martynov <mar.kolya@gmail.com> Co-authored-by: Richard Startin <richard.startin@datadoghq.com>
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.
Replaces the HTTP statuses with a more compact data structure, because they're
static finaland surprisingly large:We have between 2 and 4 of the above. This means we could have overhead between 12 and 24KB (if there is an override with a lot of status codes) depending on what configuration overrides are in place.
Using a
BitSetwe have:server errors:
and client errors
The worst case size overhead with
BitSetis ~0.5KB.This also means we can avoid wrapping status codes if we represent them with primitive types in the future.