Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(otlp-transformer): reduce allocations #4578

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Samuron
Copy link
Contributor

@Samuron Samuron commented Mar 25, 2024

Which problem is this PR solving?

The penguins are losing homes

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Just usual low hanging fruits - do not iterate map via entries(), use regular loops, less array copying via map

Fixes # (issue)

Short description of the changes

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

  • Test A

Checklist:

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

@Samuron Samuron requested a review from a team as a code owner March 25, 2024 06:35
@@ -17,7 +17,11 @@ import type { IAnyValue, IKeyValue } from './types';
import { Attributes } from '@opentelemetry/api';

export function toAttributes(attributes: Attributes): IKeyValue[] {
return Object.keys(attributes).map(key => toKeyValue(key, attributes[key]));
const result = [];
for (const key in attributes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

using x in y can have issues with some runtimes, it might still be better to use Object.keys and just avoid the map call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what runtimes? I though this is such a fundamental feature, tbh. The downside is that Object.keys will allocate array

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember the runtime, as it was around 2 years ago and it was caused (for Application Insights) by the runtime "adding" additional properties to the prototype of Object and Array which when accessed caused and exception. Let me see if I can find the PR and if I added comments for the details.

Copy link
Contributor

@MSNev MSNev Mar 27, 2024

Choose a reason for hiding this comment

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

  • AI - #1420 Fix issues with for..in usage with prototype extension libraries like ember.js and prototype.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CHANGELOG.md Outdated
@@ -11,6 +11,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* perf(otlp-transfromer): reduce allocations
Copy link
Member

Choose a reason for hiding this comment

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

this should go in experimental/CHANGELOG.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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.

None yet

3 participants