perf: Privacy at Capture — unmask-selector presence probe (experimental) - #10
Open
roggernaut wants to merge 2 commits into
Open
perf: Privacy at Capture — unmask-selector presence probe (experimental)#10roggernaut wants to merge 2 commits into
roggernaut wants to merge 2 commits into
Conversation
Bundle Size ChangesSize change: +49.28 kB (+0.45%) | Total size: 11079.33 kB
|
| File | Base | PR | Diff |
|---|---|---|---|
all.cjs |
603.81 kB | 606.84 kB | +3.04 kB (+0.50%) |
all.js |
603.48 kB | 606.51 kB | +3.04 kB (+0.50%) |
all.umd.cjs |
607.35 kB | 610.39 kB | +3.04 kB (+0.50%) |
all.umd.min.cjs |
286.41 kB | 287.70 kB | +1.29 kB (+0.45%) |
browser-client - 794.48 kB -> 804.87 kB (+10.39 kB (+1.31%))
| File | Base | PR | Diff |
|---|---|---|---|
browser-client.cjs |
227.78 kB | 230.81 kB | +3.03 kB (+1.33%) |
browser-client.js |
227.55 kB | 230.58 kB | +3.03 kB (+1.33%) |
browser-client.umd.cjs |
230.94 kB | 233.97 kB | +3.03 kB (+1.31%) |
browser-client.umd.min.cjs |
108.22 kB | 109.51 kB | +1.30 kB (+1.20%) |
record - 676.87 kB -> 687.73 kB (+10.86 kB (+1.60%))
| File | Base | PR | Diff |
|---|---|---|---|
record.cjs |
194.29 kB | 197.56 kB | +3.27 kB (+1.68%) |
record.js |
194.20 kB | 197.47 kB | +3.27 kB (+1.68%) |
record.umd.cjs |
195.31 kB | 198.34 kB | +3.03 kB (+1.55%) |
record.umd.min.cjs |
93.07 kB | 94.37 kB | +1.30 kB (+1.39%) |
rrweb - 2039.66 kB -> 2050.56 kB (+10.89 kB (+0.53%))
| File | Base | PR | Diff |
|---|---|---|---|
rrweb.cjs |
587.18 kB | 590.46 kB | +3.28 kB (+0.56%) |
rrweb.js |
586.88 kB | 590.16 kB | +3.28 kB (+0.56%) |
rrweb.umd.cjs |
588.52 kB | 591.56 kB | +3.04 kB (+0.52%) |
rrweb.umd.min.cjs |
277.09 kB | 278.38 kB | +1.29 kB (+0.47%) |
rrweb-snapshot - 702.08 kB -> 708.83 kB (+6.75 kB (+0.96%))
| File | Base | PR | Diff |
|---|---|---|---|
rrweb-snapshot.cjs |
201.81 kB | 203.86 kB | +2.05 kB (+1.02%) |
rrweb-snapshot.js |
200.40 kB | 202.42 kB | +2.02 kB (+1.01%) |
rrweb-snapshot.umd.cjs |
204.43 kB | 206.48 kB | +2.05 kB (+1.00%) |
rrweb-snapshot.umd.min.cjs |
95.45 kB | 96.08 kB | +642 B (+0.66%) |
roggernaut
force-pushed
the
privacy-at-capture-unmask-probe
branch
from
September 2, 2026 14:33
4474320 to
ffb28f3
Compare
roggernaut
force-pushed
the
privacy-at-capture-core
branch
from
September 2, 2026 19:51
ee793c7 to
da75a0f
Compare
roggernaut
force-pushed
the
privacy-at-capture-unmask-probe
branch
from
September 2, 2026 21:06
ffb28f3 to
b5322f2
Compare
…xperimental)
Every non-legacy preset compiles a non-null `unmaskTextSelector`, which
permanently forces `serializeNodeWithId`'s `checkAncestors` branch on and
re-walks ancestors with `matches()` for every node — O(nodes x depth) on a
page with no unmask target anywhere.
`resolveUnmaskTextSelector` probes once per full snapshot and once per
mutation flush (not per node) for whether the selector matches anything in the
document, walking into open shadow roots explicitly since `querySelector` does
not pierce them. When nothing matches, `null` is passed downward and the cheap
short-circuit is restored; otherwise the selector is returned unchanged. A
throwing selector is assumed present, failing closed to masking.
EXPERIMENTAL: a novel optimization with no vendor precedent. Probe cost, paid
per snapshot and per flush even where it buys nothing: one `querySelector`
plus one `querySelectorAll('*')` per root.
Paired with it, and at the same per-flush granularity, the mutation buffer
memoises `needMaskingText` results in a `Map` keyed by the element the walk
actually starts from: with `checkAncestors` on and no inherited decision the
result is a pure function of that element, so N `characterData` mutations
under one parent share a single walk. Nothing survives the flush -- between
flushes the DOM, and every ancestor chain a decision came from, is free to
change, and holding the keys would pin removed nodes in memory.
Unlike the probe, this half has direct vendor precedent: Datadog allocates one
privacy-level cache per synchronous mutation batch, sound "because we process
incremental mutations synchronously, [so] we know that privacy levels cannot
change during the process" (serializeMutations.ts:95-102). The two compose --
when the probe has nulled the selector for a flush the walk already
short-circuits and the cache costs one `Map` lookup on top of nearly nothing.
Measured on ten text mutations under one parent: 30 unmask-selector
`matches()` probes before, 3 after.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…se the probe's cost - The comment at the `snapshot()` entry claimed the unresolved policy was threaded into nested iframe documents, but the code threaded the value already resolved against the parent document. An unmask target existing only inside a same-origin iframe was therefore ignored — the parent's "nothing matches" answer masked it. The unresolved selector now rides alongside the resolved one, and the deferred iframe and stylesheet re-serializations each re-probe against their own document. - Disclose the probe's cost in the guide and changeset: it is a full-document element sweep, costliest precisely when no unmask target exists, scaling with DOM size on every flush. refactor(privacy): rename the `manual` preset to `minimal` in this layer's own addition -- the perf-smoke doc comment's "non-manual preset" reference. Clean rename, nothing released. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
roggernaut
force-pushed
the
privacy-at-capture-unmask-probe
branch
from
September 3, 2026 10:26
b5322f2 to
a64c9ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A performance optimization for the non-legacy presets.
Every non-minimal preset compiles a non-null
unmaskTextSelector—balancedandstrictalways include[data-privacy="unmask"]and the cross-vendor unmask classes, whether or not any rule configured one. That permanently forcesserializeNodeWithId'scheckAncestorsbranch on, which re-walks ancestors withElement.prototype.matchesfor every single node instead of trusting the inherited masking decision — O(nodes × depth) on a page that has no unmask target anywhere. Most pages never put anything under an unmask selector, so that walk buys nothing.resolveUnmaskTextSelectorprobes once per full snapshot and once per mutation flush — not per node — for whether the selector currently matches anything in the document.querySelector/querySelectorAllnever pierce shadow-DOM boundaries, so the probe walks into every open shadow root explicitly; otherwise it would wrongly conclude that an unmask target living inside an open shadow tree doesn't exist.When nothing matches,
nullis passed downward for that pass and the cheap short-circuit is restored. When a match exists, the selector is returned unchanged and per-node checking happens exactly as before. A selector that throws (detached or hostile document) is assumed present, so behavior fails closed to masking.Experimental
This is a novel optimization with no vendor precedent. Probe cost, paid per snapshot and per mutation flush even on pages that do have an unmask target, where it buys nothing:
querySelectorper rootquerySelectorAll('*')walk per root, to enumerate open shadow rootsMeasured benefit: on a 40-deep × 40-wide DOM under
strictwith no unmask target, totalmatches()calls drop from thousands to under 200 (asserted bytest/privacy-perf.test.ts).Layers directly on #4; independent of #8 and #9.
Tests
packages/rrweb-snapshot— 225 passed, 1 skipped (includes the two new perf guards)packages/rrwebtest/record/privacy.test.ts+test/record.test.ts— passing headless (current counts in CI)npx tsc -bclean🤖 Generated with Claude Code