Skip to content

fix(worker): Speed up BundleAnalysisSaveMeasurements by bulk inserting timeseries data - #1867

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-bundle-analysis-bulk-insert
Open

fix(worker): Speed up BundleAnalysisSaveMeasurements by bulk inserting timeseries data#1867
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-bundle-analysis-bulk-insert

Conversation

@sentry

@sentry sentry Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

The BundleAnalysisSaveMeasurements task was experiencing hard timeouts (720s) for bundle analysis reports with a large number of JavaScript assets. The root cause was identified as the _save_to_timeseries method being called and flushed individually for each JavaScript asset, leading to thousands of sequential database INSERT ... ON CONFLICT DO UPDATE operations.

This PR refactors the BundleAnalysisReportService.save_measurements method to collect all timeseries measurements (overall bundle size, individual JS asset sizes, and aggregated asset type sizes) into a single list. A new _save_to_timeseries_bulk method was introduced to perform a single bulk INSERT ... ON CONFLICT DO UPDATE operation for all collected measurements, followed by a single session.flush().

This change drastically reduces the number of database round-trips from O(N) (where N is the number of JS assets) to a constant O(1), eliminating the timeout issue and significantly improving the performance of bundle analysis measurement saving.

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes WORKER-Z5E

@codecov-notifications

codecov-notifications Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/worker/services/bundle_analysis/report.py 90.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.83%. Comparing base (d8942db) to head (f3fb9dd).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/worker/services/bundle_analysis/report.py 90.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1867      +/-   ##
==========================================
- Coverage   91.83%   91.83%   -0.01%     
==========================================
  Files        1332     1332              
  Lines       51830    51837       +7     
  Branches     1647     1647              
==========================================
+ Hits        47598    47603       +5     
- Misses       3911     3913       +2     
  Partials      321      321              
Flag Coverage Δ
workerintegration 58.49% <5.00%> (-0.02%) ⬇️
workerunit 90.38% <90.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

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.

0 participants