Skip to content
Closed
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
perf(mutation): shift n^2
  • Loading branch information
JonasBa committed Jul 29, 2023
commit 85b23bf5d65263ed355c795b457c4e3fc2b08bf9
72 changes: 44 additions & 28 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export default class MutationBuffer {
};

while (this.mapRemoves.length) {
this.mirror.removeNodeFromMap(this.mapRemoves.shift()!);
this.mirror.removeNodeFromMap(this.mapRemoves.pop()!);
}

for (const n of this.movedSet) {
Expand Down Expand Up @@ -384,12 +384,13 @@ export default class MutationBuffer {
tailNode = tailNode.previous;
// ensure _node is defined before attempting to find value
if (_node) {
const parentId = this.mirror.getId(_node.value.parentNode);
const nextId = getNextId(_node.value, this.mirror);

if (nextId === -1) continue;

const parentId = this.mirror.getId(_node.value.parentNode);

// nextId !== -1 && parentId !== -1
else if (parentId !== -1) {
if (parentId !== -1) {
node = _node;
break;
}
Expand Down Expand Up @@ -430,21 +431,33 @@ export default class MutationBuffer {
pushAdd(node.value);
}

const texts = [];
for(let i = 0; i < this.texts.length; i++){
if(!this.mirror.getId(this.texts[i].node)){
continue;
}
texts.push({
id: this.mirror.getId(this.texts[i].node),
value: this.texts[i].value,
});
}

const attributes = [];
for(let i = 0; i < this.attributes.length; i++){
if(!this.mirror.getId(this.attributes[i].node)){
continue;
}
attributes.push({
id: this.mirror.getId(this.attributes[i].node),
attributes: this.attributes[i].attributes,
});
}

const payload = {
texts: this.texts
.map((text) => ({
id: this.mirror.getId(text.node),
value: text.value,
}))
texts,
// text mutation's id was not in the mirror map means the target node has been removed
.filter((text) => this.mirror.has(text.id)),
attributes: this.attributes
.map((attribute) => ({
id: this.mirror.getId(attribute.node),
attributes: attribute.attributes,
}))
attributes,
// attribute mutation's id was not in the mirror map means the target node has been removed
.filter((attribute) => this.mirror.has(attribute.id)),
removes: this.removes,
adds,
};
Expand All @@ -462,9 +475,9 @@ export default class MutationBuffer {
this.texts = [];
this.attributes = [];
this.removes = [];
this.addedSet = new Set<Node>();
this.movedSet = new Set<Node>();
this.droppedSet = new Set<Node>();
this.addedSet.clear();
this.movedSet.clear();
this.droppedSet.clear();
this.movedMap = {};

this.mutationCb(payload);
Expand Down Expand Up @@ -673,15 +686,18 @@ export default class MutationBuffer {
* Make sure you check if `n`'s parent is blocked before calling this function
* */
private genAdds = (node: Node, t?: Node) => {
let rp = 0;
const queue: [Node, Node|undefined][] = new Array<[Node, Node|undefined]>(1000);
queue[0] = [node, t];

while (queue[rp]) {
const next = queue[rp]
if(!next) break;
let rp = -1;
let wp = -1;
queue[++wp] = [node, t];

while (rp < wp) {
const next = queue[++rp]
if(!next){
throw new Error("Add queue is corrupt, there is no next item to process")
}
const [n, target] = next;
rp++;

// this node was already recorded in other buffer, ignore it
if (this.processedNodeManager.inOtherBuffer(n, this)) continue;

Expand Down Expand Up @@ -709,12 +725,12 @@ export default class MutationBuffer {
// but we have to remove it's children otherwise they will be added as placeholders too
if (!isBlocked(n, this.blockClass, this.blockSelector, false)) {
n.childNodes.forEach((childN) => {
queue.push([childN, undefined])
queue[++wp] = [childN, undefined]
});
if (hasShadowRoot(n)) {
n.shadowRoot.childNodes.forEach((childN) => {
this.processedNodeManager.add(childN, this);
queue.push([childN, n])
queue[++wp] = [childN, n]
});
}
}
Expand Down