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

bitfields? #29126

Closed
ronag opened this issue Aug 14, 2019 · 3 comments
Closed

bitfields? #29126

ronag opened this issue Aug 14, 2019 · 3 comments
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.

Comments

@ronag
Copy link
Member

ronag commented Aug 14, 2019

Is there any reason why bitfields are not used more in NodeJS?

e.g. the readable and writable state footprint can easily be reduced by more than 50% by switching all of those different boolean flags into a single 16/32 bit bitfield. Reducing memory usage and improving CPU cache access.

Is this something worth investigating?

@ronag
Copy link
Member Author

ronag commented Aug 14, 2019

e.g. readable state

from 23 (184 bytes?):

objectMode
highWaterMark
buffer
length
pipes
flowing
ended
endEmitted
reading
sync
needReadable
emittedReadable
readableListening
resumeScheduled
paused
emitClose
autoDestroy
destroyed
defaultEncoding
awaitDrain
decoder
encoding
endEmitted

to 9 (72 byttes? almost fits in cacheline):

bitfield
highWaterMark
buffer
length
pipes
defaultEncoding
awaitDrain
decoder
encoding

@addaleax
Copy link
Member

Is this something worth investigating?

Yes. Would you be interested in opening a PR and seeing how the benchmarks go?

@ronag ronag mentioned this issue Aug 14, 2019
7 tasks
@Fishrock123 Fishrock123 added the lib / src Issues and PRs related to general changes in the lib or src directory. label Aug 14, 2019
@ronag
Copy link
Member Author

ronag commented Aug 17, 2019

@addaleax: So from my research it seems the performance improvements are small (0-10%) and some cognitive overhead is involved. The only reason this might be worth looking into is to reduce memory usage (which can be relevant for e.g. http).

Should we close this?

@ronag ronag closed this as completed Sep 22, 2019
@ronag ronag reopened this Dec 29, 2019
@ronag ronag closed this as completed Dec 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

No branches or pull requests

3 participants