Skip to content

Memoize stack trace parsing and transformation - #38

Merged
rmuratov merged 1 commit into
mainfrom
memoize-stack-trace-transform
Jul 11, 2026
Merged

Memoize stack trace parsing and transformation#38
rmuratov merged 1 commit into
mainfrom
memoize-stack-trace-transform

Conversation

@rmuratov

Copy link
Copy Markdown
Owner

Closes #30

Problem

StackTrace.create and transform (which walks every frame and calls originalPositionFor on the consumer) ran on every render of App — including renders caused by unrelated state, e.g. every keystroke in the source map textarea or a theme toggle. For large stack traces with several source maps this causes noticeable input lag.

Fix

Wrapped both steps in useMemo:

  • parsing is keyed on stackTraceInputValue,
  • transformation is keyed on sourceMaps and the parsed stackTrace.

Debouncing from the issue was left out: with memoization the expensive work only runs when its actual inputs change, and re-parsing on each stack trace keystroke is the desired behavior (the result pane updates live).

Tests

Two integration tests (memoization suite): after entering a stack trace and uploading source maps, an unrelated re-render (typing into the source map textarea) must not call StackTrace.create or the consumer's originalPositionFor again. originalPositionFor is spied on via the consumer prototype, same technique as the existing destroy spy. Both tests fail on main without the fix (verified via git stash).

Correctness of the memo dependencies is already covered by existing tests: the result updates after editing the stack trace, uploading, and deleting source maps.

Coverage stays at 100%.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sourcemap-tools with  Cloudflare Pages  Cloudflare Pages

Latest commit: 937597c
Status: ✅  Deploy successful!
Preview URL: https://a61b9d9b.sourcemap-tools.pages.dev
Branch Preview URL: https://memoize-stack-trace-transfor.sourcemap-tools.pages.dev

View logs

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8606456) to head (937597c).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #38   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          213       213           
  Branches        53        53           
=========================================
  Hits           213       213           

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

🚀 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.

@rmuratov
rmuratov merged commit 48c176b into main Jul 11, 2026
4 checks passed
@rmuratov
rmuratov deleted the memoize-stack-trace-transform branch July 11, 2026 14:35
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.

Memoize stack trace parsing and transformation

1 participant