Skip to content

Commit e67bec0

Browse files
authored
Addresses performance issues for event dispatching: Copy the original event and delete the message data after a pre-defined timeout (Dash-Industry-Forum#4744)
1 parent 453c1da commit e67bec0

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ declare namespace dashjs {
16561656
},
16571657
events?: {
16581658
eventControllerRefreshDelay?: number,
1659-
deleteEventMessageDataAfterEventStarted?: boolean
1659+
deleteEventMessageDataTimeout?: number
16601660
}
16611661
timeShiftBuffer?: {
16621662
calcFromSegmentTimeline?: boolean

src/core/Settings.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import Events from './events/Events.js';
8787
* },
8888
* events: {
8989
* eventControllerRefreshDelay: 100,
90-
* deleteEventMessageDataAfterEventStarted: true
90+
* deleteEventMessageDataTimeout: 10000
9191
* }
9292
* timeShiftBuffer: {
9393
* calcFromSegmentTimeline: false,
@@ -352,10 +352,12 @@ import Events from './events/Events.js';
352352
* @typedef {Object} EventSettings
353353
* @property {number} [eventControllerRefreshDelay=100]
354354
* Interval timer used by the EventController to check if events need to be triggered or removed.
355-
* @property {boolean} [deleteEventMessageDataAfterEventStarted=true]
356-
* If this flag is enabled the EventController will delete the message data of events after they have been started. This is to save memory in case events have a long duration and need to be persisted in the EventController.
357-
* Note: Applications will receive a copy of the original event data when they subscribe to an event. This copy contains the original message data and is not affected by this setting.
358-
* Only if an event is dispatched for the second time (e.g. when the user seeks back) the message data will not be included in the dispatched event.
355+
* @property {number} [deleteEventMessageDataTimeout=10000]
356+
* If this value is larger than -1 the EventController will delete the message data attributes of events after they have been started and dispatched to the application.
357+
* This is to save memory in case events have a long duration and need to be persisted in the EventController.
358+
* This parameter defines the time in milliseconds between the start of an event and when the message data is deleted.
359+
* If an event is dispatched for the second time (e.g. when the user seeks back) the message data will not be included in the dispatched event if it has been deleted already.
360+
* Set this value to -1 to not delete any message data.
359361
*/
360362

361363
/**
@@ -1118,7 +1120,7 @@ function Settings() {
11181120
},
11191121
events: {
11201122
eventControllerRefreshDelay: 100,
1121-
deleteEventMessageDataAfterEventStarted: true
1123+
deleteEventMessageDataTimeout: 10000
11221124
},
11231125
timeShiftBuffer: {
11241126
calcFromSegmentTimeline: false,

src/streaming/controllers/EventController.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ function EventController() {
477477
if (mode === MediaPlayerEvents.EVENT_MODE_ON_RECEIVE && !event.triggeredReceivedEvent) {
478478
logger.debug(`Received event ${eventId}`);
479479
event.triggeredReceivedEvent = true;
480-
eventBus.trigger(event.eventStream.schemeIdUri, { event: JSON.parse(JSON.stringify(event)) }, { mode });
480+
eventBus.trigger(event.eventStream.schemeIdUri, { event }, { mode });
481481
return;
482482
}
483483

@@ -494,10 +494,12 @@ function EventController() {
494494
_sendCallbackRequest(url);
495495
} else {
496496
logger.debug(`Starting event ${eventId} from period ${event.eventStream.period.id} at ${currentVideoTime}`);
497-
eventBus.trigger(event.eventStream.schemeIdUri, { event: JSON.parse(JSON.stringify(event)) }, { mode });
498-
if (settings.get().streaming.events.deleteEventMessageDataAfterEventStarted) {
499-
delete event.messageData;
500-
delete event.parsedMessageData;
497+
eventBus.trigger(event.eventStream.schemeIdUri, { event }, { mode });
498+
if (settings.get().streaming.events.deleteEventMessageDataTimeout > -1) {
499+
setTimeout(() => {
500+
delete event.messageData;
501+
delete event.parsedMessageData;
502+
}, settings.get().streaming.events.deleteEventMessageDataTimeout);
501503
}
502504
}
503505
event.triggeredStartEvent = true;

0 commit comments

Comments
 (0)