mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-29 08:52:25 +00:00
Merge pull request #2196 from PR0M3TH3AN/perf/channel-profile-render-loop-optimization-15025405161037801037
⚡ Remove dead code execution in channel profile render loop
This commit is contained in:
2 files changed
+71
-6
No files matched your search
@@ -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`);
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user