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.
Background
Older versions of Lua, such as 5.1 (which LuaJIT, and hence OpenResty, is compatible with) has trouble with really big numbers. This is why the repo's ID generator involves concatenating strings. I don't know the full details here, so please correct me if I'm missing something.
Benchmarks
Before
5m new ids: 10.136033 seconds.
After
5m new ids: 0.118243 seconds.
Code Changes
I investigated speeding ID generation up (it's a substantial portion of all CPU time), and I think that this makes it 92 times faster (woo). The existing code generates a random number between 0 and 255, which will generate a hexadecimal character between
00
andff
. For a span ID, it does this 8 times (resulting in a 16 character hexadecimal span ID); for a trace id, it does it 16 times (resulting in a 32 character hexadecimal trace id). Seebit.tohex
here: http://bitop.luajit.org/api.html.This code change moves from generating a random number between
0
and4294967295
, which isFFFFFFFF
rendered as a decimal:What to look for
Are we still generating the full range of IDs? A cursory look suggest yes: