Skip to content

Conversation

sivakumarsc
Copy link

@sivakumarsc sivakumarsc commented Aug 27, 2025

Which problem is this PR solving?

While analysing our application CPU profile, we found parsePairKeyValue from @opentelemetry/core is one of the hot function.
CPU_Profile

Fixes # (issue)

Short description of the changes

Refactor the parsePairKeyValue function to simplify the computations

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

A Benchmark test to compare the Older and newer implementation

Benchmark

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@sivakumarsc sivakumarsc requested a review from a team as a code owner August 27, 2025 16:36
Copy link

linux-foundation-easycla bot commented Aug 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Sep 3, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.06%. Comparing base (52ffa04) to head (e8085de).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
packages/opentelemetry-core/src/baggage/utils.ts 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5885      +/-   ##
==========================================
- Coverage   95.06%   95.06%   -0.01%     
==========================================
  Files         307      307              
  Lines        8031     8038       +7     
  Branches     1627     1629       +2     
==========================================
+ Hits         7635     7641       +6     
- Misses        396      397       +1     
Files with missing lines Coverage Δ
packages/opentelemetry-core/src/baggage/utils.ts 97.61% <93.33%> (-2.39%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trentm
Copy link
Contributor

trentm commented Sep 3, 2025

I haven't dug into why yet, but the new impl shows to be the same time or slower for me:

[15:39:10 trentm@peach:~/tm/opentelemetry-js4/packages/opentelemetry-core (git:refactor-parse-pair-key-value)]
% npm run test:bench

> @opentelemetry/[email protected] test:bench
> node test/performance/benchmark/index.js

parsePairKeyValue simple (old) x 5,054,037 ops/sec ±0.67% (93 runs sampled)
parsePairKeyValue simple (new) x 5,039,987 ops/sec ±0.68% (95 runs sampled)
parsePairKeyValue with metadata (old) x 4,525,204 ops/sec ±0.69% (92 runs sampled)
parsePairKeyValue with metadata (new) x 4,346,512 ops/sec ±0.58% (92 runs sampled)
parsePairKeyValue URI encoded (old) x 4,430,196 ops/sec ±0.62% (96 runs sampled)
parsePairKeyValue URI encoded (new) x 4,435,236 ops/sec ±0.61% (96 runs sampled)
parsePairKeyValue complex (old) x 3,606,884 ops/sec ±0.71% (93 runs sampled)
parsePairKeyValue complex (new) x 3,496,362 ops/sec ±0.70% (97 runs sampled)
[15:40:01 trentm@peach:~/tm/opentelemetry-js4/packages/opentelemetry-core (git:refactor-parse-pair-key-value)]
% node --version
v20.19.1

Similar on Node.js 24:

% node --version
v24.6.0
[15:41:22 trentm@peach:~/tm/opentelemetry-js4/packages/opentelemetry-core (n:24 git:refactor-parse-pair-key-value)]
% npm run test:bench

> @opentelemetry/[email protected] test:bench
> node test/performance/benchmark/index.js

parsePairKeyValue simple (old) x 5,442,733 ops/sec ±0.74% (95 runs sampled)
parsePairKeyValue simple (new) x 5,459,702 ops/sec ±0.85% (95 runs sampled)
parsePairKeyValue with metadata (old) x 4,800,913 ops/sec ±0.70% (93 runs sampled)
parsePairKeyValue with metadata (new) x 4,682,423 ops/sec ±0.76% (94 runs sampled)
parsePairKeyValue URI encoded (old) x 4,505,672 ops/sec ±0.66% (94 runs sampled)
parsePairKeyValue URI encoded (new) x 4,530,546 ops/sec ±0.95% (89 runs sampled)
parsePairKeyValue complex (old) x 3,611,070 ops/sec ±0.98% (95 runs sampled)
parsePairKeyValue complex (new) x 3,680,629 ops/sec ±0.74% (96 runs sampled)

FWIW: This is on macos 15.6.1, arm64.

@sivakumarsc
Copy link
Author

npm run test:bench

Not sure, why you are seeing different numbers with the same config.

My machine - MacOs - 15.6.1, Mac M3 pro

Node 20.11.1

Screenshot 2025-09-05 at 11 31 21 AM

Node 24.6.0
Screenshot 2025-09-05 at 11 33 53 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants