Skip to content

perf(int32): default vtkCellArray to int32 storage fork-wide (+ STL reader)#76

Merged
akaszynski merged 2 commits into
mainfrom
feat/cellarray-int32-default
Jun 19, 2026
Merged

perf(int32): default vtkCellArray to int32 storage fork-wide (+ STL reader)#76
akaszynski merged 2 commits into
mainfrom
feat/cellarray-int32-default

Conversation

@akaszynski

Copy link
Copy Markdown
Member

Summary

Make int32 the default integer-storage width for cell topology across fvtk — stock VTK defaults vtkCellArray offsets/connectivity to int64, which doubles the cell-array footprint and halves memory-bandwidth density (the bottleneck on large meshes) for the overwhelmingly common case (< 2³¹ points/cells). Integer values are identical to stock; only the container narrows ("width-relaxed" rule).

What changed

  • vtkCellArray::DefaultStorageIs64Bit = false — every new cell array defaults to int32 storage regardless of vtkIdType width.
  • Auto-promotion (safety): every value-writing path widens 32→64 bit when a value can't fit in int32, so meshes with >2³¹ points/cells stay correct (never silently truncated). The guard WidenStorageForValue is a single predicted-not-taken branch on the common path; out-of-line ConvertTo64BitStorage runs only on real overflow. Guarded: InsertNextCell (all overloads funnel through the (npts,pts)/(int) forms), InsertCellPoint, UpdateCellCount, ReplaceCellAtId, ReplaceCellPointAtId, AppendLegacyFormat (+ImportLegacyFormat), Append, SetOffset. SetData stays caller-controlled. Restore stock behaviour with SetDefaultStorageIs64Bit(true).
  • STL reader: the fast binary path now stores int32 cells when values fit (per-site, since SetData is explicit).
  • Bit-exact gate (compare.py): integer arrays compared by value normalized to int64 (container width ignored); float arrays stay strict (maxULP=0).

Validation (executor build → manylinux_2_28 container)

  • Promotion safety test PASS — inserts a >2³¹ value through every write path; each auto-promotes and round-trips the value exactly (no truncation).
  • Full bit-exact suite: 262/262 PASS (incl. common_cellarray, ply_roundtrip, locators, SMP determinism, wrapper parity).
  • STL order-relaxed harness PASS — fvtk (int32 cells) ≡ stock VTK 9.6.2 (same point set + triangle set), int32 storage confirmed.

🤖 Generated with Claude Code

akaszynski and others added 2 commits June 19, 2026 10:45
…k-wide)

Flip vtkCellArray's default offset/connectivity storage from 64-bit to 32-bit
regardless of vtkIdType width. Stock VTK defaults these to 64-bit; for the
overwhelmingly common case (meshes with < 2^31 points/cells) that doubles the
cell-array footprint and halves memory-bandwidth density -- the bottleneck on
large meshes. int32-by-default is a broad perf/memory win.

Safety: every value-writing path now auto-widens 32->64 bit when a value cannot
be represented in int32, so meshes with >2^31 points/cells stay correct. The
guard (WidenStorageForValue) is a single predicted-not-taken branch on the
common path; the out-of-line ConvertTo64BitStorage runs only on real overflow.
Guarded paths: InsertNextCell (all overloads funnel through the (npts,pts) and
(int) forms), InsertCellPoint, UpdateCellCount, ReplaceCellAtId,
ReplaceCellPointAtId, AppendLegacyFormat (and ImportLegacyFormat via it),
Append, SetOffset. SetData stays caller-controlled (explicit width choice).

Integer VALUES are identical to stock VTK; only the container narrows
(width-relaxed rule). The bit-exact gate (compare.py) now compares integer
arrays by value normalized to int64 rather than by raw container bytes, so the
int32/int64 dtype difference is not a failure; float arrays stay strict
(maxULP=0). Restore stock behaviour with SetDefaultStorageIs64Bit(true).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Apply the fvtk int32-default rule to the fast binary-STL path: store the
triangle offsets/connectivity as int32 when every value fits (numFile*3 bounds
both the largest offset and the largest vertex index), widening to int64 only
for >2^31-element meshes. Halves the cell-array footprint; values are identical
(STL order-free gate already canonicalizes). SetData is caller-controlled so it
does not pick up the vtkCellArray default automatically.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@akaszynski akaszynski merged commit 03dad82 into main Jun 19, 2026
9 checks passed
@akaszynski akaszynski deleted the feat/cellarray-int32-default branch June 19, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant