Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ [RUM-2633] Optimize DOM iteration in the recorder #2657

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

thomas-lebeau
Copy link
Collaborator

@thomas-lebeau thomas-lebeau commented Mar 19, 2024

Motivation

It was suggesting that we could improve the performance of the child node iteration by using a more efficient method.

This benchmark suggest that using nextSibling is 5 times faster than using childNodes.forEach.

In reality the improvement is not so significant for our use case (see below), however the change is pretty small and safe so it's can't hurt to implement.

Changes

Refactor forEachChildNodes() to use nextSibling instead of childNodes.forEach.

Benchmark

I've ran some benchmarks locally to get numbers that matches better our use-case.

results:

childNodes.forEach nextSibling
average time of a full snapshot 136.7 ms 131.8 ms
ops / sec 7.4 7.6

We observe a ~4% improvement which is not very significant and suggests that the bottleneck is somewhere else.

test script
const warmupStart = performance.now()

while (performance.now() - warmupStart < 2000) {
  DD_RUM.stopSessionReplayRecording()
  DD_RUM.startSessionReplayRecording()
}

const testStart = performance.now()
const measures = []

while (performance.now() - testStart < 5000) {
  const measureStart = performance.now()

  DD_RUM.stopSessionReplayRecording()
  DD_RUM.startSessionReplayRecording()

  measures.push(performance.now() - measureStart)
}

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@thomas-lebeau thomas-lebeau marked this pull request as ready for review March 19, 2024 11:23
@thomas-lebeau thomas-lebeau requested a review from a team as a code owner March 19, 2024 11:23
@thomas-lebeau
Copy link
Collaborator Author

/to-staging

@dd-devflow
Copy link
Contributor

dd-devflow bot commented Mar 19, 2024

🚂 Branch Integration: starting soon, merge in < 10m

Commit a0b82dae80 will soon be integrated into staging-12.

This build is going to start soon! (estimated merge in less than 10m)

Use /to-staging -c to cancel this operation!

dd-mergequeue bot added a commit that referenced this pull request Mar 19, 2024
…staging-12

Co-authored-by: Thomas Lebeau <thomas.lebeau@datadoghq.com>
@dd-devflow
Copy link
Contributor

dd-devflow bot commented Mar 19, 2024

🚂 Branch Integration: This commit was successfully integrated

Commit a0b82dae80 has been merged into staging-12 in merge commit ea927b4819.

Check out the triggered pipeline on Gitlab 🦊

@thomas-lebeau thomas-lebeau merged commit f9852bc into main Mar 19, 2024
18 checks passed
@thomas-lebeau thomas-lebeau deleted the thomas.lebeau/child-next-sibling branch March 19, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants