You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would certainly make it quicker if we didn't have to remove the hyphens. Or maybe there's a faster way than the regex as we know the positions of them. Ideally we'd want to avoid the extra allocation!
UUIDs are declared as either 32 character hexadecimal strings without dashes ("12c2d058d58442709aa2eca08bf20986"), or 36 character strings with dashes ("12c2d058-d584-4270-9aa2-eca08bf20986"). It is recommended to omit dashes and use UUID v4 in all cases.
But in plenty of other places it also says it expects 32 character uuids without dashes 🤷♂️
Maybe we can keep the dashes in all cases on the client but we'd give Relay extra work because they'll all need normalising to 32 characters without dashes?
Maybe we can keep the dashes in all cases on the client but we'd give Relay extra work because they'll all need normalising to 32 characters without dashes?
IMO giving relay extra work is no big deal, but we do then have friction where the uuid we display in the UI is different than the logged out json from the sdk
import{Bench,hrtimeNow}from'tinybench';import{v4asuuidv4}from'@lukeed/uuid';constbench=newBench({hrtimeNow})functiontinyBundleUuid(getRandomByte){return(([1e7])+1e3+4e3+8e3+1e11).replace(/[018]/g,c=>((c)^((getRandomByte()&15)>>((c)/4))).toString(16),);}/** This is a copy of @lukeed/uuid but without injecting hyphens */varIDX=256,HEX=[],BUFFER;while(IDX--)HEX[IDX]=(IDX+256).toString(16).substring(1);functionv4NoHyphens(){vari=0,num,out='';if(!BUFFER||((IDX+16)>256)){BUFFER=Array(i=256);while(i--)BUFFER[i]=256*Math.random()|0;i=IDX=0;}for(;i<16;i++){num=BUFFER[IDX+i];if(i==6)out+=HEX[num&15|64];elseif(i==8)out+=HEX[num&63|128];elseout+=HEX[num];// if (i & 1 && i > 1 && i < 11) out += '-';}IDX++;returnout;}bench.add('crypto.randomUUID()',()=>{console.assert(crypto.randomUUID())}).add('crypto.randomUUID().replace(/-/g, "")',()=>{console.assert(crypto.randomUUID().replace(/-/g,''))}).add('crypto.getRandomValues()',()=>{constgetRandomByte=()=>{consttypedArray=newUint8Array(1);crypto.getRandomValues(typedArray);returntypedArray[0];};console.assert(tinyBundleUuid(getRandomByte));}).add('Math.random()',()=>{letgetRandomByte=()=>Math.random()*16;console.assert(tinyBundleUuid(getRandomByte));}).add('@lukeed/uuid',()=>{console.assert(uuidv4())}).add('@lukeed/uuid (custom no hyphens)',()=>{console.assert(v4NoHyphens())});awaitbench.run()console.log(bench.name)console.table(bench.table())
This suggests we should remove the crypto.getRandomValues() code completely because it's 10x slower than Math.random().
If bundle size wasn't a concern we would probably use the modified version of @lukeed/uuid without hyphens since this is nearly twice as fast as crypto.randomUUID().replace(/-/g, "")
The performance of generateTraceId is currently quite fast in all my local tests so far. Closing this since there were some improvements made in #17938
Activity
timfish commentedon Apr 5, 2025
My testing of
uuid4()on Node v20 (ie. hittingcrypto.randomUUID()) suggests it takes under 0.001ms.Maybe
crypto.randomUUID()is being polyfilled with something that isn't as good as Nodes native code? Even then, 170ms seems suspiciously high!AbhiPrasad commentedon Apr 7, 2025
@timfish this is a sandwich view, so it's an aggregate time. Perhaps it being called so much is nothing we can avoid.
timfish commentedon Apr 8, 2025
It would certainly make it quicker if we didn't have to remove the hyphens. Or maybe there's a faster way than the regex as we know the positions of them. Ideally we'd want to avoid the extra allocation!
timfish commentedon Apr 8, 2025
Just checked develop.sentry.io and for uuids, its says:
But in plenty of other places it also says it expects 32 character uuids without dashes 🤷♂️
Maybe we can keep the dashes in all cases on the client but we'd give Relay extra work because they'll all need normalising to 32 characters without dashes?
AbhiPrasad commentedon Apr 9, 2025
IMO giving relay extra work is no big deal, but we do then have friction where the uuid we display in the UI is different than the logged out json from the sdk
timfish commentedon Oct 15, 2025
The following code:
Results in:
This suggests we should remove the
crypto.getRandomValues()code completely because it's 10x slower thanMath.random().If bundle size wasn't a concern we would probably use the modified version of
@lukeed/uuidwithout hyphens since this is nearly twice as fast ascrypto.randomUUID().replace(/-/g, "")fix(core): Improve uuid performance (#17938)
JPeer264 commentedon Jan 20, 2026
The performance of
generateTraceIdis currently quite fast in all my local tests so far. Closing this since there were some improvements made in #17938