Skip to content

Commit 8af9fbf

Browse files
authored
⚗️ Partial view updates — batch optimizations (#4807)
1 parent 2ab42e8 commit 8af9fbf

7 files changed

Lines changed: 705 additions & 105 deletions

File tree

packages/browser-core/src/transport/batch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { FlushEvent, FlushReason, UrgentFlushReason } from './flushControll
1717
export const MESSAGE_BYTES_LIMIT = 256 * ONE_KIBI_BYTE
1818

1919
export interface Batch {
20+
isEmpty: boolean
2021
add: (message: Context) => void
2122
upsert: (message: Context, key: string) => void
2223
forceFlush: (reason: FlushReason) => void
@@ -115,6 +116,9 @@ export function createBatch({
115116
}
116117

117118
return {
119+
get isEmpty() {
120+
return flushController.messagesCount === 0
121+
},
118122
add: addOrUpdate,
119123
upsert: addOrUpdate,
120124
prepareUrgentFlushObservable: flushController.prepareUrgentFlushObservable,

packages/browser-core/src/transport/flushController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export function createFlushController({ pageMayExitObservable }: FlushController
9595
flushObservable,
9696
prepareUrgentFlushObservable,
9797
forceFlush: flush,
98+
get messagesCount() {
99+
return currentMessagesCount
100+
},
98101

99102
/**
100103
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.

packages/browser-core/test/emulate/mockFlushController.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export function createMockFlushController() {
2424
flushObservable,
2525
prepareUrgentFlushObservable,
2626
forceFlush: jasmine.createSpy<FlushController['forceFlush']>(),
27+
get messagesCount() {
28+
return currentMessagesCount
29+
},
2730
} satisfies FlushController
2831

2932
return {

packages/browser-debugger/src/entries/main.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { registerCleanupTask, replaceMockableWithSpy } from '@datadog/browser-core/test'
21
import { Observable } from '@datadog/browser-core'
2+
import { registerCleanupTask, replaceMockableWithSpy } from '@datadog/browser-core/test'
33
import { initDebuggerTransport } from '../domain/api'
44
import { startDeliveryApiPolling } from '../domain/deliveryApi'
55
import { display } from '../domain/display'
@@ -39,6 +39,7 @@ describe('datadogDebugger', () => {
3939
replaceMockableWithSpy(startDebuggerBatch).and.callFake(() => ({
4040
flushObservable: new Observable(),
4141
prepareUrgentFlushObservable: new Observable(),
42+
isEmpty: false,
4243
add: () => undefined,
4344
flush: () => undefined,
4445
forceFlush: () => undefined,
@@ -72,6 +73,7 @@ describe('datadogDebugger', () => {
7273
replaceMockableWithSpy(startDebuggerBatch).and.callFake(() => ({
7374
flushObservable: new Observable(),
7475
prepareUrgentFlushObservable: new Observable(),
76+
isEmpty: false,
7577
add: () => undefined,
7678
flush: () => undefined,
7779
forceFlush: () => undefined,

0 commit comments

Comments
 (0)