Bug 146802 - [Streams API] Templating ReadableJSStream
Summary: [Streams API] Templating ReadableJSStream
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-09 13:16 PDT by youenn fablet
Modified: 2015-07-12 09:29 PDT (History)
4 users (show)

See Also:


Attachments
Patch (11.00 KB, patch)
2015-07-09 13:52 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (10.95 KB, patch)
2015-07-12 08:31 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2015-07-09 13:16:27 PDT
Templaing ReadableJSStream might allow easier support for teeing streams as well as more easily supporting ReadableByteStream.
The queue management in particular could be templatized.
Comment 1 youenn fablet 2015-07-09 13:52:31 PDT
Created attachment 256509 [details]
Patch
Comment 2 WebKit Commit Bot 2015-07-09 13:55:23 PDT
Attachment 256509 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/streams/ReadableStream.h:145:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Darin Adler 2015-07-10 09:40:15 PDT
Comment on attachment 256509 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256509&action=review

Still really concerned about the use of JSC::Strong here. I am increasingly thinking this belongs in JavaScriptCore not WebCore, despite the comments about where Blink chose to put it.

> Source/WebCore/Modules/streams/ReadableStream.h:141
> +//   Subclasses should implement error storage, pulling and cancelling.

Normally we’d say “derived classes” rather than “subclasses” to match C++ terminology.

> Source/WebCore/Modules/streams/ReadableStream.h:142
> +template <typename ChunkType>

We typically omit out the space between template and "<".

> Source/WebCore/Modules/streams/ReadableStream.h:143
> +class ReadableEnqueuingStream : public ReadableStream {

Could/should put "final" here.

> Source/WebCore/bindings/js/ReadableJSStream.h:60
> +template <>

Again, normally no space after "template". I also think this looks better on a single line, but not sure others agree.

> Source/WebCore/bindings/js/ReadableJSStream.h:61
> +class ReadableEnqueuingStream<ReadableJSStreamValue> : public ReadableStream {

Is it really helpful to have this be a class template specialization? Why not have this be a non-template class?

Related question; perhaps this should derive from ReadableEnqueuingStream<ReadableJSStreamValue> rather than from ReadableStream, for more code sharing. Then we’d want that class to not be final, but this one would be. I guess the problem with that is that it’s not OK to call the enqueueChunk feature from the base, so maybe not good to inherit that way. Too bad, though.

> Source/WebCore/bindings/js/ReadableJSStream.h:63
> +    double desiredSize() const  { return m_highWaterMark - m_totalQueueSize; }

Extra space here after "const".
Comment 4 youenn fablet 2015-07-12 07:05:58 PDT
Thanks for the review.

(In reply to comment #3)
> Comment on attachment 256509 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=256509&action=review
> 
> Still really concerned about the use of JSC::Strong here. I am increasingly
> thinking this belongs in JavaScriptCore not WebCore, despite the comments
> about where Blink chose to put 

I agree, although I think we can find workarounds to remove JSC::Strong uses.

In addition to straightforward GC, putting ReadableStream into JSC would allow us to get closer to the spec.
We would probably use UnderlyingSource to tie WebCore (HTTP, MediaStream) with JSC streams.
Part of the implementation would be done in JS as well.

Having it in WebCore ensures that the pipe between specific WebCore producer and consumer can be made efficient (HTTP to MediaStream e.g.).
I am thinking that this would still be possible to do it even if streams are in JSC, but further validating this would be good.
It was also helping to have everything in WebCore so that the queuing is made efficient (no use of promises all the time).
But early optimization is usually bad so probably not a strong point.

> 
> > Source/WebCore/Modules/streams/ReadableStream.h:141
> > +//   Subclasses should implement error storage, pulling and cancelling.
> 
> Normally we’d say “derived classes” rather than “subclasses” to match C++
> terminology.

OK

> 
> > Source/WebCore/Modules/streams/ReadableStream.h:142
> > +template <typename ChunkType>
> 
> We typically omit out the space between template and "<".

OK

> 
> > Source/WebCore/Modules/streams/ReadableStream.h:143
> > +class ReadableEnqueuingStream : public ReadableStream {
> 
> Could/should put "final" here.
> 
> > Source/WebCore/bindings/js/ReadableJSStream.h:60
> > +template <>
> 
> Again, normally no space after "template". I also think this looks better on
> a single line, but not sure others agree.

OK

> 
> > Source/WebCore/bindings/js/ReadableJSStream.h:61
> > +class ReadableEnqueuingStream<ReadableJSStreamValue> : public ReadableStream {
> 
> Is it really helpful to have this be a class template specialization? Why
> not have this be a non-template class?

That could be done too.

> 
> Related question; perhaps this should derive from
> ReadableEnqueuingStream<ReadableJSStreamValue> rather than from
> ReadableStream, for more code sharing. Then we’d want that class to not be
> final, but this one would be. I guess the problem with that is that it’s not
> OK to call the enqueueChunk feature from the base, so maybe not good to
> inherit that way. Too bad, though.

We could add an incrementSize() method and specialize it for ReadableJSStreamValue.

> 
> > Source/WebCore/bindings/js/ReadableJSStream.h:63
> > +    double desiredSize() const  { return m_highWaterMark - m_totalQueueSize; }
> 
> Extra space here after "const".

OK
Comment 5 youenn fablet 2015-07-12 08:31:21 PDT
Created attachment 256679 [details]
Patch for landing
Comment 6 youenn fablet 2015-07-12 08:34:20 PDT
(In reply to comment #5)
> Created attachment 256679 [details]
> Patch for landing

I fixed the style issues and final.
I will further check improvements at my return in two weeks.
Comment 7 WebKit Commit Bot 2015-07-12 09:29:20 PDT
Comment on attachment 256679 [details]
Patch for landing

Clearing flags on attachment: 256679

Committed r186740: <http://trac.webkit.org/changeset/186740>
Comment 8 WebKit Commit Bot 2015-07-12 09:29:23 PDT
All reviewed patches have been landed.  Closing bug.