-
Notifications
You must be signed in to change notification settings - Fork 9
WIP feat: Implement StreamWriter and StructuredIrStreamWriter for IR data streaming (based on #74). #76
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
…ion in constructor comment
…l in StructuredIrStreamWriter
…turedIrStreamWriter
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@zzxthehappiest
Sorry for the confusion. I meant to say instead of implementing a However, during prototyping, as we may find via the commit history, it was found that serializing any JS-object in C++ is quite expensive (~4x slower) because there will be a lot of cross-VM communications. Instead, I decided to serialize the object -> msgpack in JS then pass the msgpack bytes into C++ code. Luckily, it can be easily achieved via the Nevertheless, please ignore this action item for now. I am thinking of a different interface due to some limitations in the current implementation. Please see below for the explanation. In the prototype, I was hoping to implement the CLP IR writer with some common / standard interface in JavaScript, so it may work better with other (JS-standard / 3rd-party) reader / writer / transform streams. However, after conducting some throughout research this week, I found I believe some changes are needed in the interface. Here are some approaches I am picturing:
cc @LinZhihao-723 @davidlion @kirkrodrigues @hoophalab for comments, who are experts with writers in Python / Golang. I'll respond to the rest of the questions in a separate thread to avoid spamming the experts. |
I'm leaning toward the second approach (and optionally including the third). This way, we can have a writer with extended methods like We can expose a standard Junhao and I would love to hear your thoughts and discuss further: @LinZhihao-723 @davidlion @kirkrodrigues @davemarco |
@davidlion reviewed this and we discussed offline - |
If I understand correctly, we are going to try the second option with what @hoophalab proposed? |
Description
Implemented the desiredSize/ready and abort on top of #74
Done:
getLastWritePromise
: return aPromise
for the last write operation. Since theclp::WriterInterface::write
returns void, to make theWritableStream
can correctly backpressure (as the example here), we needawait writer.ready
(which is an async operation) inWebStreamWriter::write
, so it also needs to return aPromise
so in JS code thePromise
produced byawait writer.ready
can be resolved correctly, avoid memory leak after main function exits (if not doing so, there will be a memory access exception).desiredSize
: return the desiredSize property of theWritableStream
, it is a sync function.abort
: call theabort(reason)
defined in theunderlying sink
in theWritableStream
.WebStreamWriter
:await_ready
: get the readyPromise property of theWritableStream
, so that we can add callback to make theWebStreamWriter::write
correctly write the content after backpressure is finished.WebStreamWriter::write
:WritableStream
, so I make it a "fake"-async function.CMakeLists.txt
now it copies the generated.js
files to the unit test directly, so we don't need to hard code it ascmake-build-release
which is only used by Clion.ClpFfiJs-worker
, but haven't successfully run it for unknown reason.Questions:
StreamWriter::write
(link)StreamWriter::flush
(link). For theflush
I checked theCompressor.cpp
, it seems we never usem_compressed_stream_writer.flush()
so I am not sure do we really need to implement this in theWebStreamWriter
as well as modify the currentStructuredIrStreamWriter::flush
.StructuredIrStreamWriter::write
(link)StructuredIrStreamWriter::close
(link)StreamWriter::write
(link)-fwasm-exceptions
compile flag and add-sASYNCIFY=1
flag, otherwise there is compile error says the async is not supported. However, there is an apparent performance cost of it, the 1000000 write operations takes around 0.7s slower than before (2.1s -> 2.8s). It seems these two compile flags have not been supported at the same time yet in theemsk
framework. But from the stream standard,WritableStreamDefaultWriter
'sabort
,close
andwrite
are all async (they all returnPromise
, link), as well as the same functions in theunderlying sink
(link). So I think it is worth to trade off the cost to support the async feature and we can potentially gain the performance back in other places (e.g., better caching policy whenwrite
).Checklist
breaking change.
Validation performed
Run the unit test
test-node.mjs
.