Skip to content

⚗️ Partial view updates — batch optimizations#4807

Draft
mormubis wants to merge 17 commits into
mainfrom
adlrb/partial-view
Draft

⚗️ Partial view updates — batch optimizations#4807
mormubis wants to merge 17 commits into
mainfrom
adlrb/partial-view

Conversation

@mormubis

Copy link
Copy Markdown
Contributor

Motivation

The initial partial view updates implementation (already on main) sends diffs via batch.add(). Two inefficiencies: when the full VIEW is still in the current batch, intermediate updates add separate view_update events on top of it instead of replacing the VIEW in place. And when multiple updates land in the same batch, each one becomes a separate view_update instead of a single aggregate.

Changes

batch.ts — adds flushObservable: Observable<{ upsertedKeys: string[] }> to Batch. Fires after each flush with the keys that were in the upsert buffer, so subscribers know exactly which entries were sent.

startRumBatch.ts — refactored into createViewBatchRouter to make the routing logic unit-testable without the full batch setup. Two batch-level optimizations:

If the current batch already has a full VIEW, intermediate updates replace it in the upsert buffer (batchHasFullView path). No view_update emitted. Same as the non-experimental behavior.

If the batch was already flushed, updates compute an aggregate diff from batchBase (the last state the backend received) and upsert it under the same key. Multiple updates collapse to one view_update per batch.

The router subscribes to batch.flushObservable to advance batchBase and reset batchHasFullView only when the VIEW was actually included in the flush — avoiding the sync-flush state race present in the previous approach.

Test instructions

  1. yarn dev, open http://localhost:8080
  2. Add enableExperimentalFeatures: ['partial_view_updates'] to the DD_RUM.init() call in sandbox/index.html
  3. Open DevTools → Network tab, filter by /proxy

Optimization 1 (no view_update emitted):

  1. In the console, call DD_RUM.setViewName('test') — update arrives while the VIEW is still in the batch
  2. Flush: window.dispatchEvent(new Event('beforeunload'))
  3. The proxy request should contain only a full VIEW, no view_update

Optimization 2 (aggregate view_update sent):

  1. Flush first: window.dispatchEvent(new Event('beforeunload'))
  2. In the console, call DD_RUM.setViewName('test2') — update arrives in a fresh batch
  3. Flush again: window.dispatchEvent(new Event('beforeunload'))
  4. The second proxy request should be noticeably smaller — it contains a view_update diff, not a full VIEW

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change
  • Added e2e/integration tests for this change
  • Updated documentation

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jun 18, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.40 KiB 172.72 KiB +322 B +0.18%
Rum Profiler 7.88 KiB 7.88 KiB 0 B 0.00%
Rum Recorder 21.22 KiB 21.22 KiB 0 B 0.00%
Logs 54.82 KiB 54.82 KiB 0 B 0.00%
Rum Slim 130.14 KiB 130.46 KiB +322 B +0.24%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 18, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 83.33%
Overall Coverage: 77.00% (+0.13%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6537cec | Docs | Datadog PR Page | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant