Skip to content

Commit 92ea459

Browse files
committed
improve throttling in useThrottledDailyEvent
Increasing default throttle timeout to 500 drastically improves CPU & RAM when joining large calls. Also remove additional 0ms timeout.
1 parent 0a52780 commit 92ea459

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/components/DailyAudio.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ export const DailyAudio = memo(
280280
});
281281
},
282282
[assignSpeaker, localSessionId, removeSpeaker]
283-
)
283+
),
284+
200
284285
);
285286

286287
const rmpAudioIds = useParticipantIds({

src/hooks/useThrottledDailyEvent.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type EventCallback<T extends DailyEvent | DailyEvent[]> = (
3333
export const useThrottledDailyEvent = <T extends DailyEvent>(
3434
ev: T | T[],
3535
callback: EventCallback<EnsureArray<T>>,
36-
throttleTimeout = 100
36+
throttleTimeout = 500
3737
) => {
3838
const { off, on } = useContext(DailyEventContext);
3939
const eventId = useMemo(() => {
@@ -74,11 +74,7 @@ export const useThrottledDailyEvent = <T extends DailyEvent>(
7474
if (!ev) return;
7575
const addEvent = (ev: DailyEventObject) => {
7676
throttledEvents.current.push(ev);
77-
/**
78-
* A 0ms timeout allows the event loop to process additional incoming events,
79-
* while the throttle is active. Otherwise every event would be delayed.
80-
*/
81-
setTimeout(emitEvents, 0);
77+
emitEvents();
8278
};
8379
if (Array.isArray(ev)) {
8480
ev.forEach((e) => on(e, addEvent, eventId[e]));

0 commit comments

Comments
 (0)