Skip to content

Revisit sizeofvar's size heuristic for correctness/gaps (untouched in years) #5

Description

@Shinrai

Tracking issue — not urgent, just so it isn't lost.

The package was recently onboarded to the CLDMV @v4 workflow flow with a vitest characterization suite (#2). That work deliberately locked current behavior for regression safety — it did not review the underlying sizeofvar.js heuristic for correctness. The module predates recent Node/V8 and hasn't been touched in years, so the actual estimate may be stale or off.

Worth a later pass on:

  • The magic-number heuristic — the fixed costs (152 for booleans, per-8-char string buckets, the 2^31 numeric offset, the object entry-count overhead 40 + ceil((c-1)/3)*24). Whether these still reflect real V8 memory layout on current Node majors, or were ever accurate. Consider validating against process.memoryUsage() / v8.serialize sizes or Buffer.byteLength where applicable.
  • Edge cases the tests currently lock (not endorse):
    • sizeofvar(null) throws TypeError (null dispatches to the object branch, then Object.entries(null) throws).
    • undefined, functions, symbols, and bigints match no switch case and silently return 0.
    • Object cost keys on entry count, never key name/length.
      These may be bugs rather than intended behavior — decide per case whether to fix or keep.
  • Modernization (cosmetic vs. the correctness question): ESM + named export, typed signature, drop the var/old-style code.

Note: the 91-test characterization suite pins current output, so any behavior change here must update those tests deliberately (they assert what it does today, not what is correct).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions