-
Notifications
You must be signed in to change notification settings - Fork 2
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 interface #12
Comments
I'd also note Nodejs guarantees that callbacks will be called exactly once,
but as far as I can tell, there's no equivalent finalization callback in
our spec; the only option is to subscribe to every event.
I think some Promise interface would be beneficial for this.
On Jan 28, 2019 09:55, "Thom van Kalkeren" <[email protected]> wrote:
Is there any particular reason the current streams API is based on the
event-based nodejs model, rather than the promise-based whatwg spec
<https://streams.spec.whatwg.org/>?
The latter has already been deployed in most browsers, and allows any type
<https://streams.spec.whatwg.org/#model>, so passing Quad instances as
chunks would seem to be compliant, allowing full spec deference making this
spec a lot simpler and cross-compatible.
The guys over at nodejs also seem to have started on implementing the
whatwg spec <https://github.com/nodejs/whatwg-stream>, so switching might
prevent premature obsolescence.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/rdfjs/representation-task-force/issues/149>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAatDeGj9Gay0hMCVjGZ01XL4XzjASedks5vHyt9gaJpZM4aWVvo>
.
|
It's not, it's based on the subset of it that is fast 🙂
It is terribly slow still for the moment. Source: had to roll my own iterator library for an RDF query engine that uses Terms internally, because Node.js streams (one magnitude) and promise-based streams (two magnitudes) are slower. |
C-code without bounds checking should be significantly faster as well, but there are reasons why the features are there of course. One or two orders is a pretty large hit anyway, but I fear the features left out will find their way back into the spec over time (e.g. @awwright calling guarantees)
The streams interface is relatively new and will probably gain performance improvements over time, especially when native support has been written into the engine (rather than building something custom). But it's already fast enough for the guys over at facebook to use it to stream video Any promise based solution would have the overhead of instantiating, scheduling, and calling those promises, doing that for every statement separately would severely degrade performance. The current rdfjs spec emits one quad at-a-time, was the Promise-based implementation you tested also doing that? |
The low-level spec provides everything a higher-level spec needs to build in such features as back-pressure handling and promises.
Exactly.
But that's the way you do (async) streams. |
Besides the Quad streams our RDFJS packages will produce, they need to be feed by streams from other packages and need to write via streams to other packages. If you look at available, used and maintained packages, Node.js streams are the current standard. They are also available as separate package. In the latest version they can be used with Symbol.asyncIterator. As async loops are a JS language feature and not just a spec on top of JS, I think we are on the save side. This was also already discussed in #129. We also discussed it in one of the calls and we decided to use the subset of Node.js streams. As this topic was already closed some time ago, I will close this issue. If there are new strong arguments for WHATWG streams, we can open the issue anytime. |
Transfered to I tried adding
@RubenVerborgh do you refer to https://github.com/RubenVerborgh/AsyncIterator ? N3.js doesn't seem to use it. I see a lot of packages from @comunica, I see that @mcollina besides |
Nope, N3.js should work out of the box without any stream dependencies, depending on what exactly you use. |
I think the best way is to add support for async iterators - when they are available. Both streams implementation offer them, they are fast, and they are more ergonomic and intuitive. They do the right think with error handling, which is always tricky. |
Thanks @mcollina, but It's more nuanced than that:
We are keeping an eye on ES6 AsyncIterator performance (I wish we had live tests in a browser, @joachimvh), but it's not looking good. Logical, because the protocol does more than the subset of stream we use. |
Thanks @mcollina and my bad with splitting conversation between here and twitter: https://twitter.com/elfpavlik/status/1104500178432806912 We had some prior conversation where more than one person expressed 👍 for ES Asynciterator rdfjs/dataset-spec#42 (comment) |
^ On high-level. Do this on low-level, and be prepared to handle streams one magnitude slower 😉 |
Can we find a way to provide both:
Last two AFAIK have common interface but not the WHATWG ReadableStream. |
I currently don’t see a way. The different interfaces are key to performance; change them and you change performance.
|
Agreed. You can easily add async interator support to your module and achieve better usability. It also does not remove your fast API when there is a need to. |
Sounds like:
|
You can provide an implementation of Symbol.asyncIterator without using any stream library. |
I probably need to reformulate the problem. How we could implement those two parsers
So that one could use them in a web browser, parse Would all three examples above and other similar modules, provide alternative interface which would expect ES Still, currently @rdfjs modules seem to directly import node BTW it also seems that even if application would want to use fast We also have this issue, to distribute those libraries as ES modules and not depend on Common JS and bundling: rdfjs-base/parser-n3#4 Which also might have benefits in cases where application uses dynamic |
4k gzipped
yes |
We probably want an opt-in spec for ES6 AsyncIterator. Although it wouldn't be much of a spec; it's basically just ES6 AsyncIterator. We might want to add that to stream-spec itself (but might be good to have it orthogonal). |
Is there any particular reason the current streams API is based on the event-based nodejs model, rather than the promise-based whatwg spec?
The latter has already been deployed in most browsers, and allows any type, so passing
Quad
instances as chunks would seem to be compliant, allowing full spec deference making this spec a lot simpler and cross-compatible.The guys over at nodejs also seem to have started on implementing the whatwg spec, so switching might prevent premature obsolescence.
The text was updated successfully, but these errors were encountered: