Skip to content

bitfields? #29126

Closed
Closed

Description

@ronag

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?

Activity

  1. ronag commented on Aug 14, 2019

    @ronag
    MemberAuthor

    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
  2. addaleax commented on Aug 14, 2019

    @addaleax
    Member

    Is this something worth investigating?

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

  3. added
    lib / srcIssues and PRs involving general changes in the lib/ or src/ directories.
    on Aug 14, 2019
  4. ronag commented on Aug 17, 2019

    @ronag
    MemberAuthor

    @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?

  5. reopened this on Dec 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lib / srcIssues and PRs involving general changes in the lib/ or src/ directories.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions