Skip to content

Perf improvements when adding metrics#307

Merged
bdeitte merged 14 commits intomainfrom
feature/cpu-perf-improvements
Mar 1, 2026
Merged

Perf improvements when adding metrics#307
bdeitte merged 14 commits intomainfrom
feature/cpu-perf-improvements

Conversation

@bdeitte
Copy link
Owner

@bdeitte bdeitte commented Feb 22, 2026

A small list (after some rechecking on things) of perf improvements to make

Copilot AI review requested due to automatic review settings February 22, 2026 00:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces several CPU performance optimizations for hot-shots, a Node.js client for StatsD, DogStatsD, and Telegraf. The changes focus on reducing redundant string operations, object allocations, and function calls in hot paths when sending metrics.

Changes:

  • Pre-join global tags into a cached string to avoid repeated string concatenation and joining operations
  • Optimize overrideTags helper with a fast path that concatenates arrays when tags don't overlap
  • Replace process.hrtime() with process.hrtime.bigint() for simpler, more efficient timing calculations
  • Eliminate unnecessary Buffer.from() conversions for TCP/STREAM protocols
  • Cache and reuse Buffer.byteLength calculations

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/transport.js Refactored addEol to use early return and handle string inputs directly
lib/statsd.js Added _globalTagStr cache for pre-joined global tags, optimized Buffer handling for TCP/STREAM, reused messageBytes variable
lib/statsFunctions.js Replaced process.hrtime() array operations with process.hrtime.bigint() for simpler time delta calculations
lib/helpers.js Implemented fast path in overrideTags to avoid expensive filtering when tags don't overlap, switched from plain object to Map for better performance
CHANGES.md Documented the performance improvements in the changelog

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bdeitte bdeitte merged commit 8c15552 into main Mar 1, 2026
13 checks passed
@bdeitte bdeitte deleted the feature/cpu-perf-improvements branch March 1, 2026 18:18
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