Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cc90576
perf(snapshot): optimize code flow of slimDomExcluded
JonasBa Jul 28, 2023
18ca335
perf(snapshot): remove lowerIfExists
JonasBa Jul 28, 2023
ba66b77
perf(snapshot): return early
JonasBa Jul 28, 2023
dc4c7b1
perf(snapshot): test
JonasBa Jul 29, 2023
85b23bf
perf(mutation): shift n^2
JonasBa Jul 29, 2023
bad990b
perf(mutation): improve process
JonasBa Jul 30, 2023
5d59621
fix(mutation): revert regexp exec
JonasBa Aug 1, 2023
58ab15c
fix(prettier): apply formatting
JonasBa Aug 1, 2023
011e0d0
Merge branch 'master' into jb/perf/replay
JonasBa Aug 3, 2023
f6c8738
fix: filter condition
JonasBa Aug 3, 2023
e6bb17e
fix: remove unused import
JonasBa Aug 3, 2023
a927384
fix: lint
JonasBa Aug 3, 2023
23512e6
test: update snapshots
JonasBa Aug 3, 2023
510d82d
revert(genAdds): revert queue implementation
JonasBa Aug 7, 2023
fab0d3d
revert(genAdds): revert snapshot
JonasBa Aug 7, 2023
e188253
feat(benchmark): add blockClass and blockSelector benchmarks
JonasBa Aug 10, 2023
12dc788
Merge branch 'master' into jb/perf/replay
JonasBa Aug 10, 2023
8750f7f
Revert "feat(benchmark): add blockClass and blockSelector benchmarks"
JonasBa Aug 10, 2023
5b05e6b
ref(perf): less recursion and a few minor optimizations
JonasBa Aug 10, 2023
074fdd9
Revert "ref(perf): less recursion and a few minor optimizations"
JonasBa Aug 10, 2023
eab4b25
ref(perf): less recursion
JonasBa Aug 10, 2023
eed46b0
fix(lint): format doc
JonasBa Aug 10, 2023
bc2c8f2
Merge branch 'master' into jb/perf/replay
JonasBa Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "ref(perf): less recursion and a few minor optimizations"
This reverts commit 5b05e6b.
  • Loading branch information
JonasBa committed Aug 10, 2023
commit 074fdd9dd69502e32356b68f6136f8a0130bf537
13 changes: 4 additions & 9 deletions packages/rrdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,11 @@ export class Mirror implements IMirror<RRNode> {
// removes the node from idNodeMap
// doesn't remove the node from nodeMetaMap
removeNodeFromMap(n: RRNode) {
const queue = [n];
const id = this.getId(n);
this.idNodeMap.delete(id);

while (queue.length > 0) {
const n = queue.pop()!;
const id = this.getId(n);
this.idNodeMap.delete(id);

if (n.childNodes) {
n.childNodes.forEach((childNode) => queue.push(childNode));
}
if (n.childNodes) {
n.childNodes.forEach((childNode) => this.removeNodeFromMap(childNode));
}
}
has(id: number): boolean {
Expand Down
30 changes: 10 additions & 20 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ export function _isBlockedElement(

try {
if (typeof blockClass === 'string') {
if(!element.classList.length) return false;
if(element.classList.length === 1 && element.classList[0] === blockClass) {
return true;
}
if (element.classList.contains(blockClass)) {
return true;
}
Expand Down Expand Up @@ -343,12 +339,9 @@ export function needMaskingText(
? (node as HTMLElement)
: node.parentElement;

if (!el) return false;

if (el === null) return false;
try {
if (typeof maskTextClass === 'string') {
if(!el.classList.length) return false;
if(el.classList.length === 1 && el.classList[0] === maskTextClass) return true;
if (el.classList.contains(maskTextClass)) return true;
if (el.matches(`.${maskTextClass} *`)) return true;
} else {
Expand Down Expand Up @@ -664,14 +657,14 @@ function serializeElementNode(
const len = n.attributes.length;
for (let i = 0; i < len; i++) {
const attr = n.attributes[i];
if (ignoreAttribute(tagName, attr.name, attr.value)) continue;

attributes[attr.name] = transformAttribute(
doc,
tagName,
toLowerCase(attr.name),
attr.value,
);
if (!ignoreAttribute(tagName, attr.name, attr.value)) {
attributes[attr.name] = transformAttribute(
doc,
tagName,
toLowerCase(attr.name),
attr.value,
);
}
}
// remote css
if (tagName === 'link' && inlineStylesheet) {
Expand Down Expand Up @@ -1061,10 +1054,7 @@ export function serializeNodeWithId(
id = genId();
}

const serializedNode = {
..._serializedNode,
id,
};
const serializedNode = Object.assign(_serializedNode, { id });
// add IGNORED_NODE to mirror to track nextSiblings
mirror.add(n, serializedNode);

Expand Down
24 changes: 5 additions & 19 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ export class Mirror implements IMirror<Node> {
getId(n: Node | undefined | null): number {
if (!n) return -1;

if(!this.nodeMetaMap.has(n)) {
return -1;
}

const id = this.getMetaId(n);
const id = this.getMeta(n)?.id;

// if n is not a serialized Node, use -1 as its id.
return id ?? -1;
Expand All @@ -123,26 +119,16 @@ export class Mirror implements IMirror<Node> {
return this.nodeMetaMap.get(n) || null;
}

getMetaId(n: Node): number | null {
return this.getMeta(n)?.id ?? null;
}

// removes the node from idNodeMap
// doesn't remove the node from nodeMetaMap
removeNodeFromMap(n: Node) {
const id = this.getId(n);
this.idNodeMap.delete(id);

const removeQueue = [n];

while(removeQueue.length){
const node = removeQueue.pop()!;
this.idNodeMap.delete(this.getId(node));

if (node.childNodes) {
node.childNodes.forEach(c => removeQueue.push(c))
}

if (n.childNodes) {
n.childNodes.forEach((childNode) =>
this.removeNodeFromMap(childNode as unknown as Node),
);
}
}
has(id: number): boolean {
Expand Down
56 changes: 23 additions & 33 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,39 +769,33 @@ function isParentRemoved(
mirror: Mirror,
): boolean {
if (removes.length === 0) return false;
return _isParentRemoved(removes, n, mirror, new Set());
return _isParentRemoved(removes, n, mirror, undefined);
}

function _isParentRemoved(
removes: removedNodeMutation[],
n: Node,
mirror: Mirror,
removeSet: Set<number>,
removeSet: Set<number> | undefined,
): boolean {
const queue = [n];
while (queue.length) {
const { parentNode } = queue.pop()!;
if (!parentNode) {
return false;
}
const { parentNode } = n;
if (!parentNode) {
return false;
}

const parentId = mirror.getId(parentNode);
if (removeSet.has(parentId)) {
const removedLookupSet = removeSet || new Set();
const parentId = mirror.getId(parentNode);
for (let i = 0; i < removes.length; i++) {
const removedNode = removes[i];
if (removedNode.id === parentId) {
return true;
}

for (let i = 0; i < removes.length; i++) {
const removedNode = removes[i];
if (removedNode.id === parentId) {
return true;
}
removeSet.add(removedNode.id);
}

queue.push(parentNode);
removedLookupSet.add(removedNode.id);
}

return false;
if (removedLookupSet.has(parentId)) {
return true;
}
return _isParentRemoved(removes, parentNode, mirror, removedLookupSet);
}

function isAncestorInSet(set: Set<Node>, n: Node): boolean {
Expand All @@ -810,16 +804,12 @@ function isAncestorInSet(set: Set<Node>, n: Node): boolean {
}

function _isAncestorInSet(set: Set<Node>, n: Node): boolean {
const queue = [n];
while (queue.length) {
const { parentNode } = queue.pop()!;
if (!parentNode) {
return false;
}
if (set.has(parentNode)) {
return true;
}
queue.push(parentNode);
const { parentNode } = n;
if (!parentNode) {
return false;
}
if (set.has(parentNode)) {
return true;
}
return false;
return _isAncestorInSet(set, parentNode);
}
10 changes: 1 addition & 9 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,13 @@ export function isBlocked(
node.nodeType === node.ELEMENT_NODE
? (node as HTMLElement)
: node.parentElement;

if (!el) return false;

try {
if (typeof blockClass === 'string') {
if(!checkAncestors){
if(el.classList.length === 1) return el.classList[0] === blockClass;
return el.classList.length > 0 && el.classList.contains(blockClass);
}

if(el.classList.length === 1) return el.classList[0] === blockClass || el.matches(`.${blockClass} *`);
return (
el.classList.length > 0 &&
el.classList.contains(blockClass) ||
el.matches(`.${blockClass} *`)
(checkAncestors && el.matches(`.${blockClass} *`))
);
}
return classMatchesRegex(el, blockClass, checkAncestors);
Expand Down