Skip to content

Keep 3MF imports responsive and bound archive expansion - #32

Open
Greg-J wants to merge 2 commits into
CNCKitchen:mainfrom
Greg-J:fix/3mf-texture-ui-blocking
Open

Greg-J wants to merge 2 commits into
CNCKitchen:mainfrom
Greg-J:fix/3mf-texture-ui-blocking

Conversation

@Greg-J

@Greg-J Greg-J commented Oct 31, 2026 •

Copy link
Copy Markdown

3MF imports can freeze the interface while extracting textures, and tiny malformed ZIP headers can make the readers attempt multi-gigabyte allocations. Move texture extraction off the UI thread and check the complete directory before expanding any selected entry.

The texture worker is short-lived, transfers expanded images back, and terminates on completion or failure. The original archive stays intact for mesh parsing and project saving. Untextured files skip the worker. Failures reject the import while preserving the current scan, measurements, draft and history.

Both model and texture readers now share the existing 1 GiB project-archive budget. The preflight counts model/relationship/configuration files and textures together, including 3MFs nested in projects, before the first decompression. It accounts for the allocation fields used by both stored and deflated entries. Ignored thumbnails and slicer sidecars are not expanded or counted; there is no new member-count or per-entry cap. Oversized input produces an actionable error.

The responsiveness experiment used a generated 4K PNG in a 40.5 MB 3MF. Median synchronous extraction dropped from 1,154.5 ms to 11 ms; the largest event-loop gap dropped from 1,157 ms to 97.7 ms (three runs, Chrome with 4× main-thread CPU slowdown). Canvas readback remains on the main thread. Workers are not equally throttled, so this demonstrates UI responsiveness, not equal-CPU throughput. scripts/bench-3mf-textures.mjs reproduces the synthetic workload.

Regression evidence:

  • Actual bundled fflate runs behind a test allocator that refuses large allocations. The original readers attempt 2 GiB allocations from tiny archives; the guarded readers reject before allocating. Combined model/texture budget and mismatched stored-entry sizes have failing-before/passing-after cases too.
  • Exact texture colours, retained archive bytes, worker disposal, live scene, project save/reopen and injected worker failure are checked through browser paths.
  • Oversized model, texture and nested-project imports preserve source, scene, worker mesh, measurement, draft and undo/redo identities. Valid packages with many small entries and ignored sidecars remain supported.

Related: #28 by Jozkah proposes 512-member, 256 MiB entry and 512 MiB total limits. This takes an alternative approach: reuse the existing project budget, inspect all selected members before the first allocation, and avoid limits on unused sidecars or member count. The two patches overlap and should be reconciled rather than stacked blindly. This PR is independent of #22, #23 and #31 and contains no automation, startup/memory optimization or design-overhaul files.

Validation:

  • Full integration gate: 3,111 unit tests, 123 MCP tests, production build and every executable browser suite pass. Private scooter fixture unavailable and skipped; 24 unit cases skipped and one todo.
  • Isolated upstream-based branch: 36 relevant unit tests, plugin-boundary and units checks, build, archive-rejection, textured-3MF and import browser suites pass.
  • Independent production preview: bundled texture worker requested; red texture rendered; exact source bytes saved; project reopened through the worker and rendered again.
  • Chrome only. No Safari/Firefox, private scan accuracy or physical hardware claim.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for the pull request. ScanRuler is dual-licensed (AGPL and commercial), which only works if its author may license every line of it, so a short Contributor License Agreement is needed once. You keep your copyright. To sign, reply with the sentence below exactly:


I agree to CLA.md


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@Greg-J Greg-J changed the title Prevent UI stalls while extracting 3MF textures Keep 3MF imports responsive and bound archive expansion Oct 31, 2026
@CNCKitchen

Copy link
Copy Markdown
Owner

The archive limits have landed since (src/core/parsers/archiveLimits.ts, in 0.9.x), so the part of this that's still new is moving texture extraction off the UI thread. It needs the CLA signed once, just reply with

I agree to CLA.md

and please rebase it on main, keeping only the worker part. If it isn't signed by November 16, I'll close this and look at the textures on my side.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants