perf(replay): reduce DOM accessor overhead and add benchmarks - #4801
perf(replay): reduce DOM accessor overhead and add benchmarks#4801marandaneto wants to merge 1 commit into
Conversation
|
Replay incident risk checkThis diff touches code involved in past incidents. This is a heads-up, not a verdict: read the matched sections of INCIDENTS.md and answer their review questions before merging. For a judgment on whether this diff has the same failure mode, run the |
| if (!untaintedAccessor) return instance[accessor]; | ||
|
|
||
| untaintedAccessorCache[cacheKey] = untaintedAccessor; | ||
| cache[accessor as string] = untaintedAccessor; |
Prompt To Fix All With AI### Issue 1
packages/browser/scripts/benchmark-replay.md:4-5
**Performance thresholds are missing**
The new benchmark explicitly provides no acceptance thresholds or statistical criteria, so it collects measurements but cannot automatically identify a performance regression. This violates the repository requirement that performance tests define clear thresholds, such as average duration and standard deviation. That requirement must be satisfied before merging.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "perf(replay): reduce DOM accessor overhe..." | Re-trigger Greptile |
| mocked replay requests. Uses the installed Playwright Chromium (no external sites | ||
| or new dependencies). Timing numbers are evidence, not machine-independent CI |
There was a problem hiding this comment.
Performance thresholds are missing
The new benchmark explicitly provides no acceptance thresholds or statistical criteria, so it collects measurements but cannot automatically identify a performance regression. This violates the repository requirement that performance tests define clear thresholds, such as average duration and standard deviation. That requirement must be satisfied before merging.
Rule Used: Performance tests should have clear thresholds, su... (source)
Learned From
PostHog/posthog#32520
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browser/scripts/benchmark-replay.md
Line: 4-5
Comment:
**Performance thresholds are missing**
The new benchmark explicitly provides no acceptance thresholds or statistical criteria, so it collects measurements but cannot automatically identify a performance regression. This violates the repository requirement that performance tests define clear thresholds, such as average duration and standard deviation. That requirement must be satisfied before merging.
**Rule Used:** Performance tests should have clear thresholds, su... ([source](https://app.greptile.com/posthog-org-19734/-/custom-context?memory=2fe31af0-f290-43bc-b879-4c1a73b3ac28))
**Learned From**
[PostHog/posthog#32520](https://github.com/PostHog/posthog/pull/32520)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Size Change: +7.71 kB (+0.04%) Total Size: 20.5 MB 📦 View Changed
ℹ️ View Unchanged
|
posthog-js Compliance ReportDate: 2026-09-05 16:35:06 UTC ✅ All Tests Passed!26/26 tests passed Capture Tests✅ 26/26 tests passed View Details
|
|
not a considerable improvement but its still worth since its a small change |
Problem
Large session replay snapshots and structural mutations still block the main thread on node-dense pages. Profiling the built SDK found that rrweb repeatedly constructs composite string keys when looking up its cached native DOM getters.
This is a small first improvement for #4217, not a complete fix. DOM capture and parts of payload encoding remain synchronous.
Changes
pnpm benchmark:replaycommand. It exercises the built SDK through mocked replay transport with compression on and off, checks intermediate replay state and privacy sentinels, and reports long tasks, frame gaps, CPU, heap deltas, drops and extra full snapshots.Performance results
Three unprofiled repetitions per arm on a roughly 50k-node fixture in Playwright Chromium 136.0.7103.25, with no CPU throttling. Both builds use the same generation-aware benchmark. These are descriptive local samples, not statistically significant estimates or customer-level guarantees.
Median longest observed main-thread task:
Uncompressed rebuild performance was essentially unchanged. No oversized mutation drops were observed in this comparison, and replay-state and privacy assertions passed. The recorder artifact increased by 110 bytes before compression and 27 bytes with gzip.
The benchmark records artifact hashes and environment metadata. It deliberately separates profiled runs from timing comparisons. A zero longest-task result means no observed task reached the Long Tasks API's 50 ms threshold, not zero blocking.
Validation
e9058295e8b060a9c847bdb4f0872fa144e041be, with no actionable findings.No recorder configuration, event ordering, masking policy, sampling or session lifecycle behavior changes. No recording-volume change is expected. Encoding-tail and asynchronous snapshot work will be evaluated separately.
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
posthog-jspatch changeset🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with Pi using repository inspection, Chromium profiling, focused tests and an independent review. The work keeps synchronous recording semantics and avoids importing the time-sliced snapshot implementation from the earlier closed PRs.
The pre-commit code formatter attempted to reformat entire rrweb files, although the root formatting command excludes rrweb. Only that hook was skipped to retain the existing rrweb style. Other hooks and targeted formatting checks passed. No changes were made to hook configuration.