Skip to content

[Extractors] Cache model reads and parallelize the vmap assembler - #7

Merged
billy1arm merged 1 commit into
mangosfour:masterfrom
r-log:feat/m4-thread-vmap-assembler
Jul 1, 2026
Merged

[Extractors] Cache model reads and parallelize the vmap assembler#7
billy1arm merged 1 commit into
mangosfour:masterfrom
r-log:feat/m4-thread-vmap-assembler

Conversation

@r-log

@r-log r-log commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Builds on the merged --threads extractor work (#5): parallelizes the vmap assembler (TileAssembler::convertWorld2), the last fully-serial phase.

Algorithmic win (helps serial too): calculateTransformedBound re-read and re-parsed each model file once per spawn — millions of redundant reads. A per-model vertex cache (iModelVertexCache) reads each unique model once and reuses it across all its spawns.

Parallelism: convertWorld2 is restructured into three phases —

  1. one global parallel pass computing every spawn's transformed bound (replaces the per-map bound loop, removing the giant-continent-map thread imbalance),
  2. a serial per-map pass building/writing the BIH .vmtree/.vmtile,
  3. a parallel convert-model-files pass.

Thread count comes from the existing -t/--threads option (0 = auto-detect cores, 1 = serial).

Correctness: output is unchanged — on the mangosthree in-tree extractor a byte-for-byte compare of the assembled vmaps (cached+parallel vs. the original serial assembler, same dir_bin) is identical. Built green here.

Numbers (full 4.3.4 reference extraction): assemble phase ~81s → ~17s threaded; the cache alone cuts the serial assemble ~81s → ~24s.


This change is Reviewable

The assembler's per-spawn bound calculation re-read and re-parsed each
model file once per spawn -- millions of redundant reads. Cache each
unique model's vertices on first read (iModelVertexCache) and reuse them
across all of that model's spawns.

Restructure convertWorld2 into three phases:
  1. one global parallel pass computing every spawn's transformed bound
     (replaces the per-map bound loop, removing the giant-continent-map
     thread imbalance),
  2. a serial per-map pass building and writing the BIH .vmtree/.vmtile,
  3. a parallel convert-model-files pass.

Thread count comes from the existing -t/--threads option (0 = auto-detect
cores, 1 = serial). Output is unchanged: a byte-for-byte compare of the
assembled vmaps (cached vs. original) is identical. On a full 4.3.4
extraction the assemble phase drops ~81s -> ~17s threaded, and the cache
alone cuts the serial assemble ~81s -> ~24s.
@billy1arm
billy1arm merged commit 6d0594a into mangosfour:master Jul 1, 2026
@r-log
r-log deleted the feat/m4-thread-vmap-assembler branch July 5, 2026 14:47
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.

2 participants