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

chore: lazy load internal request module #519

Merged
merged 18 commits into from
Mar 20, 2024

Conversation

duncanista
Copy link
Contributor

@duncanista duncanista commented Mar 18, 2024

What does this PR do?

Reduces memory allocation for this package by lazy loading internal request.ts methods.

Before:
Screenshot 2024-03-20 at 3 19 36 PM

After:
Screenshot 2024-03-20 at 3 17 40 PM

Motivation

It was possible to reduce the memory allocations + performance.

Testing Guidelines

  • Integration tests remained the same.
  • Unit tests passed as normal
  • Memory allocation was reduced.

Additional Notes

SVLS-4628

Allocation time can vary, but now we are sure that the lazy load is in effect.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 89.28571% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 81.90%. Comparing base (e08ad86) to head (a1247d1).

❗ Current head a1247d1 differs from pull request most recent head 6cc0816. Consider uploading reports for the commit 6cc0816 to get more accurate results

Files Patch % Lines
src/metrics/listener.ts 87.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #519      +/-   ##
==========================================
- Coverage   81.95%   81.90%   -0.06%     
==========================================
  Files          54       54              
  Lines        2206     2205       -1     
  Branches      512      513       +1     
==========================================
- Hits         1808     1806       -2     
+ Misses        334      333       -1     
- Partials       64       66       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@duncanista duncanista marked this pull request as ready for review March 20, 2024 19:20
@duncanista duncanista requested a review from a team as a code owner March 20, 2024 19:20
@@ -56,7 +54,7 @@ export interface MetricsConfig {
}

export class MetricsListener {
private currentProcessor?: Promise<Processor>;
private currentProcessor?: Promise<any>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly, this has to stay as it, so we don't import and load the modules that add 1MB of memory allocation.

@@ -33,6 +33,8 @@ export function unpatchHttp() {
}

function patchMethod(mod: typeof http | typeof https, method: "get" | "request", contextService: TraceContextService) {
if (mod[method].__wrapped !== undefined) return; // Only patch once
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was missed, required so no repeated logs appear.

Copy link
Contributor

@purple4reina purple4reina left a comment

Choose a reason for hiding this comment

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

This is the best thing since sliced bread.

@duncanista duncanista merged commit 78c1900 into main Mar 20, 2024
25 checks passed
@duncanista duncanista deleted the jordan.gonzalez/lazy-load-fallback-processor branch March 20, 2024 20:10
const processor = new Processor(apiClient, metricsBatchSendIntervalMS, config.shouldRetryMetrics);
processor.startProcessing();
return processor;
if (!this.isExtensionRunning && !this.config.logForwarding) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

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.

4 participants