8000 `bit` objects carry heavyweight `physical`/`virtual` attribute wrappers · Issue #136 · r-lib/bit · GitHub
[go: up one dir, main page]

Skip to content

bit objects carry heavyweight physical/virtual attribute wrappers #136

Backlog

Description

@MichaelChirico

Every bit object stores two empty lists (physical and virtual) with nested attribute pairlists just to hold vmode = "boolean" and Length = n. This imposes measurable overhead on every bit allocation and length lookup:

object.size(bit(1L))
# 1520 bytes  (vs 520 bytes with a flat scalar Length attribute — ~3x overhead)

b <- bit(10L)
system.time(for (i in 1:100000) length(b))
# ~0.52s  (vs ~0.018s with a flat Length attribute — ~29x slower)

system.time(for (i in 1:50000) bit(10L))
# ~0.35s  (vs ~0.16s with a flat Length attribute — ~2.2x slower)

In a future release, bit objects could store Length directly as a flat attribute while keeping full backwards compatibility:

  • physical.bit() and virtual.bit() synthesize list(vmode = "boolean") and list(Length = attr(x, "Length")) lazily on demand (with physical<-.bit / virtual<-.bit only attaching extra storage if a caller sets custom non-default attributes).
  • length.bit() (and internal length lookups) check flat Length first and fall back to virtual$Length so external constructors such as ff:::as.bit.ff() continue to work without breaking.
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0