Skip to content

Conversation

@timfish
Copy link
Collaborator

@timfish timfish commented Oct 15, 2025

I did some benchmarking:

┌─────────┬─────────────────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                               │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ 'crypto.randomUUID()'                   │ '269.64 ± 0.24%' │ '250.00 ± 0.00'  │ '3879372 ± 0.01%'      │ '4000000 ± 0'          │ 3708647 │
│ 1       │ 'crypto.randomUUID().replace(/-/g, "")' │ '445.09 ± 6.08%' │ '417.00 ± 0.00'  │ '2377301 ± 0.01%'      │ '2398082 ± 0'          │ 2246729 │
│ 2       │ 'crypto.getRandomValues()'              │ '32130 ± 9.11%'  │ '28083 ± 834.00' │ '35202 ± 0.07%'        │ '35609 ± 1076'         │ 31124   │
│ 3       │ 'Math.random()'                         │ '1929.0 ± 1.02%' │ '1916.0 ± 42.00' │ '525124 ± 0.01%'       │ '521921 ± 11413'       │ 518396  │
│ 4       │ '@lukeed/uuid'                          │ '273.79 ± 0.07%' │ '250.00 ± 0.00'  │ '3770742 ± 0.01%'      │ '4000000 ± 0'          │ 3652395 │
│ 5       │ '@lukeed/uuid (custom no hyphens)'      │ '262.20 ± 5.68%' │ '250.00 ± 0.00'  │ '4089440 ± 0.01%'      │ '4000000 ± 0'          │ 3813889 │
└─────────┴─────────────────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘

I found that in Node.js at least, getting a single byte via crypto.getRandomValues() is 10x slower than the Math.random() version so we should drop getRandomValues usage entirely.

I also found that for the Math.random() fallback code, we generated the base starting string (10000000100040008000100000000000) on every call to uuid4(). If we cache this value we get a ~20% improvement in this path.

In the browser crypto.randomUUID() is only available in secure contexts so our fallback code should have good performance too!

@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.63 kB -0.09% -20 B 🔽
@sentry/browser - with treeshaking flags 23.11 kB -0.13% -29 B 🔽
@sentry/browser (incl. Tracing) 40.97 kB -0.07% -25 B 🔽
@sentry/browser (incl. Tracing, Replay) 79.29 kB -0.03% -21 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.97 kB -0.03% -15 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 83.99 kB -0.03% -24 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 96.16 kB -0.02% -18 B 🔽
@sentry/browser (incl. Feedback) 41.3 kB -0.07% -26 B 🔽
@sentry/browser (incl. sendFeedback) 29.29 kB -0.02% -3 B 🔽
@sentry/browser (incl. FeedbackAsync) 34.22 kB -0.11% -36 B 🔽
@sentry/react 26.31 kB -0.15% -39 B 🔽
@sentry/react (incl. Tracing) 42.97 kB -0.06% -24 B 🔽
@sentry/vue 29.11 kB -0.07% -19 B 🔽
@sentry/vue (incl. Tracing) 42.75 kB -0.09% -36 B 🔽
@sentry/svelte 24.64 kB -0.1% -24 B 🔽
CDN Bundle 26.9 kB -0.15% -40 B 🔽
CDN Bundle (incl. Tracing) 41.62 kB -0.07% -25 B 🔽
CDN Bundle (incl. Tracing, Replay) 77.87 kB -0.05% -37 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 83.35 kB -0.03% -21 B 🔽
CDN Bundle - uncompressed 78.86 kB -0.12% -89 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 123.44 kB -0.08% -89 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 238.48 kB -0.04% -89 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 251.24 kB -0.04% -89 B 🔽
@sentry/nextjs (client) 45.11 kB -0.06% -24 B 🔽
@sentry/sveltekit (client) 41.4 kB -0.05% -17 B 🔽
@sentry/node-core 50.75 kB -0.07% -33 B 🔽
@sentry/node 154.38 kB -0.02% -22 B 🔽
@sentry/node - without tracing 92.61 kB -0.05% -44 B 🔽
@sentry/aws-serverless 106.33 kB -0.02% -20 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,392 - 9,626 -13%
GET With Sentry 1,320 16% 1,431 -8%
GET With Sentry (error only) 5,905 70% 6,284 -6%
POST Baseline 1,163 - 1,207 -4%
POST With Sentry 480 41% 528 -9%
POST With Sentry (error only) 1,031 89% 1,070 -4%
MYSQL Baseline 3,214 - 3,383 -5%
MYSQL With Sentry 335 10% 514 -35%
MYSQL With Sentry (error only) 2,614 81% 2,745 -5%

View base workflow run

@timfish timfish force-pushed the timfish/fix/improve-uuid-perf branch from 00f3d58 to 42ece80 Compare October 15, 2025 11:12
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@AbhiPrasad AbhiPrasad merged commit 40bcc3d into develop Oct 21, 2025
193 checks passed
@AbhiPrasad AbhiPrasad deleted the timfish/fix/improve-uuid-perf branch October 21, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants