Skip to content

Conversation

@jpollock-ampl
Copy link

@jpollock-ampl jpollock-ampl commented Mar 19, 2025

Sync the splitCSS performance improvements.

git cherry-pick dc20cd45cc63058325784444af6bd32ed2cace48
git cherry-pick 3e9e42fdfd6349087d7a0345af1b39dd56528502

- Fix bug where the right split point was not being picked for the 3rd section onwards
- Fix that it wasn't able to find a split when both halves were identical
- Add test to put splitCssText through it's paces with a large file
- Introduce a limit on the iteration which causes the 'efficiently' test to fail
- Fix poor 'crawling' performance in the 'matching' algorithm for large css texts - e.g. for a (doubled) benchmark.css, we were running `normalizeCssText` 9480 times before `k` got to the right place
- Further algorithm efficiency: need to take larger jumps; use the scaling factor to make better guess at how big a jump to make
Fixes a browser 'lock up' at record time due to a presence of large amounts of css in <style> elements, which are split over multiple text nodes, which triggers the new code added in rrweb-io#1437 (see that PR for full explanation of why this all exists).  rrweb-io#1437 was not written with performance in mind as it was believed to be an edge case, but things like Grammarly browser extension (rrweb-io#1603) among other scenarios were triggering pathological behavior, some of which was solved in rrweb-io#1615.
See also rrweb-io#1640 (comment) for further discussion.

* Fix the case when there are multiple matches and we end up not finding a unique one - just go with the best guess when there are many splits by looking at the previous chunk's size
* Also add '0px' -> '0' stylesheet normalization, which also fixes the sample problem in a different way
* Add new test and modify it so that it can trigger a failure in the absence of the '0px' normalization; there may be other unknown ways of triggering a similar bug, so ensure that the primary 'best guess' method doesn't suffer a regression
* Leverage the 'best guess' method so that we can quit after 100 iterations trying to find a unique substring; hopefully this bit along with the `iterLimit` already added will prevent any future pathological cases.

Failing example extracted from large files identified by Paul D'Ambra (Posthog) ... see comment from MartinWorkfully: PostHog/posthog-js#1668
@changeset-bot
Copy link

changeset-bot bot commented Mar 19, 2025

🦋 Changeset detected

Latest commit: f84a96d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@amplitude/rrweb-snapshot Patch
@amplitude/rrweb Patch
@amplitude/rrdom Patch
@amplitude/rrdom-nodejs Patch
@amplitude/rrweb-player Patch
@amplitude/rrweb-all Patch
@amplitude/rrweb-replay Patch
@amplitude/rrweb-record Patch
@amplitude/rrweb-types Patch
@amplitude/rrweb-packer Patch
@amplitude/rrweb-utils Patch
@amplitude/rrweb-web-extension Patch
@amplitude/rrvideo Patch
@amplitude/rrweb-plugin-console-record Patch
@amplitude/rrweb-plugin-console-replay Patch
@amplitude/rrweb-plugin-sequential-id-record Patch
@amplitude/rrweb-plugin-sequential-id-replay Patch
@amplitude/rrweb-plugin-canvas-webrtc-record Patch
@amplitude/rrweb-plugin-canvas-webrtc-replay Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jpollock-ampl jpollock-ampl marked this pull request as ready for review March 24, 2025 21:54
@jpollock-ampl jpollock-ampl merged commit 7824d62 into master Mar 24, 2025
11 checks passed
@github-actions github-actions bot mentioned this pull request Mar 24, 2025
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