-
Notifications
You must be signed in to change notification settings - Fork 364
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
WHATWG Streams implementation #544
Comments
Hi @jackkleeman. Thanks for considering contributing. #2 would almost be a requirement due to performance since there is no JIT in quick JS JavaScript implementation would be very slow. There is already a native rust implementation of a simple and incomplete streams API used by |
ok, i understand that we need a native implementation, and we have some initial work that we can extend, and that we should probably try and do this iteratively adding different parts of the api. will try and kick something off in the coming weeks! |
i have started work on this. indeed the spec is absolutely huge.... however, i think taking shortcuts will just make things harder tbh than just faithfully transferring the spec function by function (which seems to be what firefox devs did, for example). so thats what i am doing over in https://github.com/jackkleeman/llrt/tree/streams |
@jackkleeman I took a peek in your repo and you've seen to have had amazing progress in such short time. Fantastic! Anything we can do to help? |
@richarddavison thanks! all good for now. im currently working on getting the readable streams web platform tests all working so we can maybe get that into a PR and i can move on to writeable |
Latest update: the readable streams tests all pass, and most of the byte stream tests too. I am entering a very busy time at work so will probably take a pause for a few weeks. |
Fantastic! Take your time, I've been silently keeping an eye on your fork and you've done amazing work! Hats off 🎩 |
if you are keeping an eye on it, any feedback about the horrible OwnedBorrowMut (for stream, controller and reader) mess would be appreciated. You don't realise how much the rust borrow checker does for you until you start having to grapple with its rules being enforced at runtime.... Maybe this is unavoidable. I have considered having some sort of struct to contain all three, but due to the combinations of different readers and controllers, I don't know if this will really make things any simpler. And more generally, there is the fact that refactoring into more sensible things (eg, remove the cyclical references stream -> controller -> stream) will depart from the spec. Even now, my understanding of the end to end flow of (eg) a byte is poor simply because of the complexity, and I rely on being extremely close to the spec for things to work. Anyway, if you have an opinion on this, id love to hear it! |
Sidenote while its in my brain - quickjs has no arraybuffer transfer function. I have tried to think of a way to hack it on the rquickjs side, but I don't think its possible as we don't control the arraybuffer constructor and so its tricky to change the fact that it will be dropped by quickjs when the quickjs-ng have implemented this function. I don't think it would be hard to contribute to quickjs. For the time being we can get around it by just copying the bytes, but this may lead to some tests that don't pass, if they have ways to detect for this. Plus, it will lead to a fair few copies, because the spec really likes transferring array buffers. |
Not at the moment. I would need to have a closer look at everything you've built to see how it works.
No it does not (as its an ES2024 feature) but it allows you access the raw underlying byte slice (which causes the holding ArrayBuffer to detach them). Take a look here:
|
I don't think it detaches, unless I'm mistaken? You can get a slice to the bytes, but it still owns it, and when GC'd it will |
No you are right, it doesn't automatically. We can detach it by calling detach() but that would also cause it to be dropped/freed. |
@jackkleeman you've probably noticed but we have now merged QuickJS-NG so |
sweet! ive started on writable stream, which seems to be a lot less moving parts than readable, so hopefully i am 80% of the way done. still quite busy at work but I find moments to make progress :) |
update - writable streams all passing. i rebased and transfer works also |
currently we are at 10k additions just for the rust changes... open question how we can move towards getting this merged |
This is fantastic news 🎉 I'm really excited about this development. I recon the first step should be replacing I anticipate that we'll need to make some adjustments to optimize for a stream that avoids interactions with the JavaScript layer. For example, piping to an fs.writeStream should allow bytes to flow directly to the target |
ok, i will look to do a PR that replaces the existing llrt_stream. the stream spec has a ton of special casing (its 80% of the complexity, honestly) for bytes, including a mode where you can provide your own reusable buffer for byte transport, so its possible it will work out the box for the fs use cases. but lets see! |
I'm fairly interested in contributing an implementation of the web stream API. As I see it there are two options:
I would probably lean towards doing the latter, either as a separate crate if it can be abstracted well or simply within this repo. Are there any opinions on how this should be done? Thanks!
The text was updated successfully, but these errors were encountered: