Reduce generated Span ID range to fit in Fixnum #1189
Merged
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.
Ruby transparently handles small and large integers using the Integer object. Behind the scenes, a number could either be a Fixnum or Bignum.
A Fixnum "Holds Integer values that can be represented in a native machine word (minus 1 bit)", and thus requiring no auxiliary memory to be represented.
Fixnums are faster to create and manipulate.
The transparent boundary between Fixnums and Bignums, in the positive integer range, is around
2**62
:In the tracer, we were generating random span ids up to
2**63
, meaning half the generated ids were internally Bignums.This PR reduces the range of internally generated span ids** to up to
2**62-1
. The limit of this new range is still sufficient to produce unique ids for the purpose of tracing.This does not affect spans received from external sources: those are still handled as-is, without modification.
Also, this PR fixes our sampling logic that performs Knuth's sampling algorithm to use the correct maximum range: before we were using
2**63
, but our specs require our sampling to be consistent across languages, specially when possibly handling externally provided span ids. The specs require2**64
to be the sampling range limit. This fix can be seen in "Datadog::RateSampler#sample?".Benchmark results
For our critical path benchmark, that measures span creation up until the hand-off to the background worker: