Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] [WIP] Remove MediaSourceContentInitializer, add CoreInterface #1627

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

peaBerberian
Copy link
Collaborator

@peaBerberian peaBerberian commented Jan 13, 2025

Based on #1630 as performance regression is the main risk here

This is a proof-of-concept where I try to put in common the "content initialization" logic for our "multithread" mode and our monothreaded mode.

The idea is to replace that mode-specific code to a very thin layer (here called CoreInterface) between our "init" code (always running in main thread) and our "core" code (in a WebWorker in "multithread" mode) which would handle both modes:

  • in multithreaded mode, it would be the part doing postmessage calls and onmessage registering for thread communication

  • in monothreaded mode, it would just do the same thing through a very simple EventEmitter-like approach

Or written another way: "multithread" and single-threaded mode would now share the same logic beside the communication system used at the frontier between the main-thread and potential worker.

The end goal is to remove a lot of code, and to reduce the difference between the multithreaded and monothreaded logic, so our tests (integration, manual tests etc.) actually almost test the two in one go.

There might be some performance lost due to steps we are now performing unnecessarily when in monothreaded mode (e.g. we serialize the Manifest structure even though it's not needed when a single thread is used, we create another PlaybackObserver on the core even though the main thread one could be re-used etc.). To see if that lead to a visible difference and if it does, it shouldn't be that hard to work-around.

@peaBerberian peaBerberian added work-in-progress This Pull Request or issue is not finished yet poc Proof Of Concept - This is just an attempt to ponder on labels Jan 13, 2025
@peaBerberian peaBerberian force-pushed the poc/common-init branch 5 times, most recently from 7569943 to 47b4bf7 Compare January 13, 2025 18:22
@peaBerberian peaBerberian force-pushed the poc/common-init branch 3 times, most recently from a203984 to d97c89e Compare January 13, 2025 18:55
@peaBerberian peaBerberian added the skip-performance-checks Performance tests are not run on this PR label Jan 13, 2025
@peaBerberian peaBerberian added skip-performance-checks Performance tests are not run on this PR and removed skip-performance-checks Performance tests are not run on this PR labels Jan 13, 2025
@peaBerberian peaBerberian force-pushed the poc/common-init branch 3 times, most recently from c632c93 to 33ce62e Compare January 22, 2025 09:40
@canalplus canalplus deleted a comment from github-actions bot Jan 22, 2025
@canalplus canalplus deleted a comment from github-actions bot Jan 22, 2025
Copy link

Automated performance checks have been performed on commit 33ce62e4e447be809cf82bff3d7580535d482ebb with the base branch dev.

Tests results

✅ Tests have passed.

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 19.37ms -> 19.74ms (-0.367ms, z: 5.79347) 26.70ms -> 26.85ms
seeking 13.78ms -> 13.87ms (-0.087ms, z: 0.35110) 11.10ms -> 11.10ms
audio-track-reload 25.52ms -> 26.09ms (-0.576ms, z: 8.98430) 37.35ms -> 37.95ms
cold loading multithread 47.02ms -> 46.78ms (0.241ms, z: 9.82778) 69.00ms -> 67.95ms
seeking multithread 14.49ms -> 15.18ms (-0.690ms, z: 1.48246) 10.20ms -> 10.35ms
audio-track-reload multithread 25.28ms -> 25.19ms (0.088ms, z: 1.33883) 37.35ms -> 37.20ms
hot loading multithread 15.01ms -> 14.91ms (0.099ms, z: 3.02923) 21.60ms -> 21.45ms

If you want to skip performance checks for latter commits, add the skip-performance-checks label to this Pull Request.

@peaBerberian peaBerberian removed skip-performance-checks Performance tests are not run on this PR work-in-progress This Pull Request or issue is not finished yet poc Proof Of Concept - This is just an attempt to ponder on labels Jan 22, 2025
This is a proof-of-concept where I try to put in common the "content
initialization" logic for our "multithread" mode and our monothreaded
mode.

The idea is to replace that mode-specific code to a very thin layer
(here called `CoreInterface`) between our "init" code (always running in
main thread) and our "core" code (in a WebWorker in "multithread" mode)
which would handle both modes:

  - in multithreaded mode, it would be the part doing `postmessage` calls
    and `onmessage` registering for thread communication

  - in monothreaded mode, it would just do the same thing through a very
    simple EventEmitter-like approach

Or written another way: "multithread" and single-threaded mode would now
share the same logic beside the communication system used at the frontier
between the main-thread and potential worker (respectively
`src/main_thread` code and `src/core` code).

The end goal is to remove a lot of code, and to reduce the difference
between the multithreaded and monothreaded logic, so our tests
(integration, manual tests etc.) actually almost test the two in one go.

There might be some performance lost due to steps we are now performing
unnecessarily when in monothreaded mode (e.g. we serialize the Manifest
structure even though it's not needed when a single thread is used, we
create another PlaybackObserver on the core even though the main thread
one could be re-used etc.). To see if that lead to a visible difference
and if it does, it shouldn't be that hard to work-around.
Copy link

Automated performance checks have been performed on commit 3126d2ea86bede6de091b33465f31f36cffe1710 with the base branch dev.

Tests results

✅ Tests have passed.

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 19.86ms -> 20.79ms (-0.928ms, z: 9.54337) 27.45ms -> 28.35ms
seeking 12.06ms -> 13.39ms (-1.332ms, z: 1.74973) 11.25ms -> 11.40ms
audio-track-reload 26.09ms -> 26.56ms (-0.462ms, z: 8.96137) 38.25ms -> 39.00ms
cold loading multithread 48.14ms -> 47.59ms (0.546ms, z: 10.51482) 70.50ms -> 69.45ms
seeking multithread 17.41ms -> 19.38ms (-1.974ms, z: 0.98402) 10.50ms -> 10.50ms
audio-track-reload multithread 26.09ms -> 25.91ms (0.184ms, z: 2.72903) 38.40ms -> 38.10ms
hot loading multithread 15.53ms -> 15.42ms (0.107ms, z: 2.13895) 22.35ms -> 22.35ms

If you want to skip performance checks for latter commits, add the skip-performance-checks label to this Pull Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant