diff --git a/benchmarks/render_loop_overhead_bench.js b/benchmarks/render_loop_overhead_bench.js new file mode 100644 index 00000000..e4c3e559 --- /dev/null +++ b/benchmarks/render_loop_overhead_bench.js @@ -0,0 +1,71 @@ +// benchmarks/render_loop_overhead_bench.js + +class WatchHistoryTelemetry { + persistMetadataForVideo(video, pointerInfo) { + // Deprecated - effectively a no-op in real code + } +} + +class ModalCoordinator { + constructor() { + this.watchHistoryTelemetry = new WatchHistoryTelemetry(); + } + persistWatchHistoryMetadataForVideo(video, pointerInfo) { + if (this.watchHistoryTelemetry) { + this.watchHistoryTelemetry.persistMetadataForVideo(video, pointerInfo); + return; + } + } +} + +class App { + constructor() { + this._modal = new ModalCoordinator(); + this._coordinatorsReady = true; // Simulating initialized state + } + + _initCoordinators() { + if (this._coordinatorsReady) return; + this._coordinatorsReady = true; + } + + persistWatchHistoryMetadataForVideo(...args) { + this._initCoordinators(); + return this._modal.persistWatchHistoryMetadataForVideo(...args); + } +} + +const app = new App(); +const video = { id: "test", title: "test" }; +const pointerInfo = { key: "test" }; + +const ITERATIONS = 100_000_000; + +console.log(`Benchmarking overhead for ${ITERATIONS.toLocaleString()} iterations...`); + +const startWithCall = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + if ( + pointerInfo && + typeof app?.persistWatchHistoryMetadataForVideo === "function" + ) { + app.persistWatchHistoryMetadataForVideo(video, pointerInfo); + } +} +const endWithCall = performance.now(); +const durationWithCall = endWithCall - startWithCall; + +const startWithoutCall = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + // Simulating the removal of the call + if (false) { // Condition becomes false or code is removed + // Removed + } +} +const endWithoutCall = performance.now(); +const durationWithoutCall = endWithoutCall - startWithoutCall; + +console.log(`With call: ${durationWithCall.toFixed(2)}ms`); +console.log(`Without call: ${durationWithoutCall.toFixed(2)}ms`); +console.log(`Improvement: ${(durationWithCall - durationWithoutCall).toFixed(2)}ms`); +console.log(`Relative improvement: ${(durationWithCall / durationWithoutCall).toFixed(2)}x`); diff --git a/js/channelProfile.js b/js/channelProfile.js index 83cf0913..e590072a 100644 --- a/js/channelProfile.js +++ b/js/channelProfile.js @@ -4690,12 +4690,6 @@ export async function renderChannelVideosFromList({ typeof app?.deriveVideoPointerInfo === "function" ? app.deriveVideoPointerInfo(video) : null; - if ( - pointerInfo && - typeof app?.persistWatchHistoryMetadataForVideo === "function" - ) { - app.persistWatchHistoryMetadataForVideo(video, pointerInfo); - } const shareUrl = typeof app?.buildShareUrlFromEventId === "function"