-
Couldn't load subscription status.
- Fork 3.4k
[libwebaudio.js] Convert to handle allocator. NFC #25649
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
base: main
Are you sure you want to change the base?
Conversation
2be5458 to
a7f761b
Compare
Also: - Removing duplication in precondition check. - Use `dbg()` for debug messages The use of the HandleAllocator does add about 70 bytes to the JS payload, but that will be amortized over the different places where HandleAllocator is also uses.
Taking a peek at what currently uses HandleAllocator, I see
in e.g. my AudioWorklet MOD player, https://clbri.com/modplayer/ , I'm not sure that it will ever use libfetch, libpromise, libwasmfs_opfs or libwebsocket. So it is not clear that this change will be a win. The handle allocator itself is a bit contentious. It has a couple of challenges:
Then the last line will not result in an error, but will silently connect the node to
Losing these would not be end of the world, but I am not sure what the upside of centralizing these dependencies is? |
|
Regarding your concerns (1) and (2), I completely agree. I do think we can and should address those. The nice thing about centralizing this mechanism is that when we do fix either (1) or (2) then all the subsystems that use the handle allocator will benefit. If we have N different allocation system then we cannot systematically address those kinds of issues. Regarding (3), I'm not sure I agree, emscripten is full of shared abstractions and IMHO they have been a net win. e.g. I do agree that (1) and (2) need to be address though, so maybe we can address them before landing this change since those concerns apply to all subsystems that use the HandleAllocator, right? I just though one other nice thing that we can do once all subsystem share a common handle allocator: we can make handles globally unique (at least in debug builds). This was we can prevent even more types of programming errors: where handles from one API are mistakenly passed as handles into another API.. maybe less common but certainly good prevent type confusion. |
|
Marking this as draft until (1) and (2) can be addressed. The debugging changes I split out into #25655 |
But if we don't share the code, then the issue that needs benefiting would not even arise.
That is true. I am not arguing that all shared abstractions are bad. But I am arguing that there should be actual substance to the sharing. Here with HandleAllocator, the sharing seems to be about abstracting over a JS
It is quite rare for that to cause issues, e.g. passing a Web Audio context handle into a Fetch API call, is something that is really uncommon problem (as opposed to e.g. the use-after-free example above) to occur by a developer in the first place, and the browser JS API endpoints will croak about such issues anyways. |

Also:
dbg()for debug messagesThe use of the HandleAllocator does add about 70 bytes to the JS
payload, but that will be amortized over the different places where
HandleAllocator is also uses.