Skip to content

feat: Implement improved side effects cleaning - #34

Open
benjaminrobinet wants to merge 2 commits into
plutotcool:mainfrom
benjaminrobinet:feat/better-side-effects-clearing
Open

benjaminrobinet wants to merge 2 commits into
plutotcool:mainfrom
benjaminrobinet:feat/better-side-effects-clearing

Conversation

@benjaminrobinet

@benjaminrobinet benjaminrobinet commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

I faced some performance issues after few Renderer creation / closing.
Tried to improve it a bit. Might contain some AI slope.

Summary

  • Cancellable stream loop — Demuxer.demuxStream now returns a cancel() function. Calling it stops the background read loop, cancels the underlying reader, and rejects any pending loaded() promises. Previously the loop ran to completion regardless of whether the consumer was still alive.

  • Decoder tears down its stream on close — Decoder stores the cancel from demuxStream and calls it in close() (and before starting a new loadStream). The onLoadFrames callback and all frame callbacks guard against closed, so no frames are processed and no VideoDecoder is touched after teardown.

  • No more VideoDecoder resurrection — TrackDecoder.set() now returns immediately when closed instead of reconfiguring a closed VideoDecoder. TrackDecoder.load() re-creates the decoder lazily when reloading after a close, keeping the load → close → load cycle working. output() also guards against being called post-close.

  • Complete and idempotent Renderer.close() — The VAO is now deleted, all GL handles are nulled after deletion, and WEBGL_lose_context.loseContext() is called to immediately free the WebGL2 context slot (browsers cap active contexts at ~8–16; exceeding this caused the freezing). close() is safe to call multiple times. Public methods (load, loadStream, seek, progress, set, initialize) throw 'Renderer is closed' after teardown.

@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown

@benjaminrobinet is attempting to deploy a commit to the plutotcool Team on Vercel.

A member of the Team first needs to authorize it.

@juliendargelos

Copy link
Copy Markdown
Member

Thanks, can you add tests for the new behaviors introduced by these changes ?

@benjaminrobinet

Copy link
Copy Markdown
Contributor Author

Done @juliendargelos :)

@benjaminrobinet

Copy link
Copy Markdown
Contributor Author

Any updates on this @juliendargelos ?

This branch has not been deployed

No deployments
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.

2 participants