Skip to content

perf(core): eliminate allocations in emit hot path#185

Merged
HugoRCD merged 1 commit intomainfrom
perf/emit-hot-path
Mar 14, 2026
Merged

perf(core): eliminate allocations in emit hot path#185
HugoRCD merged 1 commit intomainfrom
perf/emit-hot-path

Conversation

@HugoRCD
Copy link
Copy Markdown
Owner

@HugoRCD HugoRCD commented Mar 14, 2026

Summary

  • Reuse a module-level Date object via isoNow() instead of new Date().toISOString() on every emit — eliminates 1 heap allocation per call (pattern used by pino)
  • Skip TailSamplingContext object allocation when no tail sampling is configured (the default/common case) — saves 1 object + 5 property assignments per emit
  • Guard override merging with if (overrides) instead of (overrides ?? {}) — avoids allocating an empty object when no overrides are passed

These target emitWideEvent (45% CPU in CodSpeed profiling) and emit() directly.

- Reuse a module-level Date object instead of allocating new Date()
  on every emit/addLog call (isoNow helper)
- Skip TailSamplingContext object allocation when no tail sampling
  is configured (the common case)
- Avoid empty object allocation when emit() is called without
  overrides
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Mar 14, 2026 7:53pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 14, 2026

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

Unknown scope "core" found in pull request title "perf(core): eliminate allocations in emit hot path". Scope must match one of: docs, playground, evlog, nuxthub, deps, repo, nuxt, nitro, next, tanstack-start, hono, express, elysia, fastify, nestjs, sveltekit, workers, fs, dx.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark report

Bundle size

Threshold: 5% · 🔴 larger · 🟡 warning · 🟢 smaller · ⚪ unchanged · 🆕 new

Status Entry Base (gzip) Current (gzip) Change Raw delta
framework/nitro 6.85 kB 6.85 kB 0.0% 0 B
framework/next 3.02 kB 3.02 kB 0.0% 0 B
adapter/sentry 2.33 kB 2.33 kB 0.0% 0 B
adapter/otlp 2.09 kB 2.09 kB 0.0% 0 B
enrichers 1.92 kB 1.92 kB 0.0% 0 B
framework/sveltekit 1.54 kB 1.54 kB 0.0% 0 B
adapter/posthog 1.48 kB 1.48 kB 0.0% 0 B
adapter/fs 1.42 kB 1.42 kB 0.0% 0 B
pipeline 1.35 kB 1.35 kB 0.0% 0 B
adapter/axiom 1.30 kB 1.30 kB 0.0% 0 B
browser 1.21 kB 1.21 kB 0.0% 0 B
error 1.21 kB 1.21 kB 0.0% 0 B
framework/nestjs 1.21 kB 1.21 kB 0.0% 0 B
adapter/better-stack 1.08 kB 1.08 kB 0.0% 0 B
framework/elysia 1.06 kB 1.06 kB 0.0% 0 B
framework/fastify 1010 B 1010 B 0.0% 0 B
workers 960 B 960 B 0.0% 0 B
framework/express 702 B 702 B 0.0% 0 B
framework/hono 593 B 593 B 0.0% 0 B
toolkit 243 B 243 B 0.0% 0 B
core (index) 205 B 205 B 0.0% 0 B
types 31 B 31 B 0.0% 0 B
logger 3.74 kB 3.74 kB -0.1% -794 B
utils 1.41 kB 1.41 kB -0.3% -76 B
Total 37.88 kB 37.87 kB -0.0% -870 B

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 14, 2026

npm i https://pkg.pr.new/evlog@185
npm i https://pkg.pr.new/@evlog/nuxthub@185

commit: 2f8061b

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 14, 2026

Merging this PR will degrade performance by 50.38%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
❌ 8 regressed benchmarks
✅ 82 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
emit minimal event 132.5 µs 95.6 µs +38.6%
duration match 25.2 µs 44.6 µs -43.41%
evlog 149.1 µs 115.2 µs +29.41%
path glob match 25.4 µs 44.6 µs -42.95%
status match 25.4 µs 51.1 µs -50.38%
winston 452.6 µs 565.5 µs -19.96%
no match (fast path) 25.6 µs 45.4 µs -43.67%
full emit with sampling (likely sampled out) 72 µs 61.3 µs +17.48%
emit + JSON.stringify 144.5 µs 107 µs +35.05%
winston — 4 separate log calls 431.6 µs 592.1 µs -27.11%
push 100 events (no flush) 424.2 µs 563.9 µs -24.78%
push 1000 events (no flush) 1.8 ms 2.6 ms -27.75%
Firefox Linux 219.3 µs 87.5 µs ×2.5
with traceparent 472.7 µs 337.6 µs +40.02%

Comparing perf/emit-hot-path (2f8061b) with main (609ad97)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (08798bc) during the generation of this report, so 609ad97 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@HugoRCD HugoRCD merged commit b76a069 into main Mar 14, 2026
15 of 18 checks passed
@HugoRCD HugoRCD deleted the perf/emit-hot-path branch March 14, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant