Skip to content
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

Binary protocol to avoid JSON encoding/decoding typed arrays (performance, bandwidth) vs. duplex-emitter #5

Open
deathcap opened this issue Feb 2, 2014 · 2 comments

Comments

@deathcap
Copy link
Owner

deathcap commented Feb 2, 2014

duplex-emitter JSON encodes everything, even Uint8Array's (binary data, exploding from 1 byte up to 4 bytes. 255 => 255,)

http://nodejs.org/api/stream.html - supports 'object mode', possibly useful?

@deathcap
Copy link
Owner Author

deathcap commented Feb 3, 2014

Trying to understand the reason for duplex-emitter exactly..

https://npmjs.org/package/duplex-emitter
https://github.com/pgte/duplex-emitter

describes it as "Turns a duplex stream into an event emitter".

But http://nodejs.org/api/stream.html says "All streams are EventEmitters" - so why do duplex streams have to be turned into event emitters if they already are?

Looking at the code, appears that duplex-emitter serializes/deserializes the events into JSON then pipes to/from the streams. Uses https://npmjs.org/package/stream-combiner and https://npmjs.org/package/split to parse NDJ - Newline Delimited JSON. Two problems:

@kumavis
Copy link

kumavis commented Feb 24, 2014

Streams are event emitters, but they only emit events about the stream (got data, went into error state). The duplexEmitter allows you to emit your own events (set a voxel, new client joined, avatar position update). I found this to be an easy way to program client-server interaction. That said, network throughput is a significant limiting factor, so we should squeeze as much perf as possible out of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants