-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Labels: simpler/faster stringlabels encoding #16069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I like the idea, we just need to agree that Also, just thinking out loud, we could take this a step further. This way, it's incremental. (actually, with the current approach, I think we can make the 3 bytes store number from |
Every branch slows it down. This is why I went for a very simple scheme. |
I missed that, I even re-ran the benchmarks, but I have an Arm x) |
Found myself looking at the assembly for regressions, apparently hoisting (I thought
helps speed up some of them, the change also makes that 1-byte case "identical" with the code in main.
Still Note that only the 1-byte case in I also need to run this on ARM. |
Meh, I don't much care how fast it goes if you abuse the Prometheus data model. |
Instead of using varint to encode the size of each label, use a single byte for size 0-254, or a flag value of 255 followed by the size in 3 bytes little-endian. This reduces the amount of code, and also the number of branches in commonly-executed code, so it runs faster. The maximum allowed label name or value length is now 2^24 or 16MB. Memory used by labels changes as follows: * Labels from 0 to 127 bytes length: same * From 128 to 254: 1 byte less * From 255 to 16383: 2 bytes more * From 16384 to 2MB: 1 byte more * From 2MB to 16MB: same Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Goes noticeably faster on AMD64 architecture. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Also add test that shows the problem. Credit to @dgl. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Slightly more user-friendly than encoding bad data and finding out when we decode. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
b835d3b
to
78ab02a
Compare
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Added @machine424's change which makes a decent improvement on amd64. Latest benchmark comparison against main (8487ed8).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Yes some of the cases results are intriguing, I even got completely different results on different AMD CPUs (lost the diff unfortunately). |
Instead of using varint to encode the size of each label, use a single byte for size 0-254, or a flag value of 255 followed by the size in 3 bytes little-endian.
This reduces the amount of code, and also the number of branches in commonly-executed code, so it runs faster.
The maximum allowed label name or value length is now 2^24 or 16MB.
Memory used by labels changes as follows:
Benchmarks - Go 1.24.0, x64:
Benchmarks - Go 1.24.0, ARM64: