Repository navigation
perf(kernel): build OCCT with the FixSelfIntersectWire hoist patch - #81
Merged
Merged
Conversation
gerchowl
force-pushed
the
feature/74-occt-hoist-patch
branch
from
October 12, 2026 21:20
a956a6f to
0cb256f
Compare
gerchowl
force-pushed
the
feature/74-occt-hoist-patch
branch
from
October 13, 2026 08:56
0cb256f to
8765e01
Compare
gerchowl
force-pushed
the
feature/74-occt-hoist-patch
branch
from
October 13, 2026 09:46
d01c58b to
cf90325
Compare
This was referenced Oct 13, 2026
Closed
ShapeFix_IntersectionTool::FixSelfIntersectWire fetched edge1 from the wire's NCollection_Sequence on every inner iteration, an O(n) walk, so healing a wire was O(n^3). flake.nix now builds nixpkgs' OCCT 7.9.3 with nix/patches/occt-7.9.3-fixselfintersectwire-hoist.patch: edge1 is fetched once per num1 and again after the big-segment branch's removals, the one branch that changes position num1 and stays in the loop. The dev shell and the kernel derivation both link it; a patch that does not apply fails the build and another OCCT version fails evaluation. kernel/occt-patch-check and tests/occt_patch.rs hold the linked OCCT to the patch: the growth exponent of the fix on convex polygons (3.0 unpatched, 2.0 patched) and 200 generated wires, 91 through the big-segment branch, fixed exactly as the unpatched OCCT recorded. Corpus: 0 of 401 files differ. Ultimaker 3: identical mesh and topology, transfer 28.8 s instead of 35.0-36.4 s. NOTICE describes the modification. Refs: #74
A plain `cmake -S kernel` source build no longer builds the test tool; `just kernel` and the flake's kernel derivation turn it on, so tests/occt_patch.rs still finds it beside the kernel. Also ends the CHANGELOG entry with a period. Refs: #74
occt-patch-check built each grid point as gp_Pnt2d(rng(), rng()), and C++ leaves the order of function arguments unspecified: clang draws x first, GCC y. On Linux every one of the 200 wires came out different, so occt_patch failed there on all seeds. Two statements fix the order to clang's, so tests/occt-patch/wires.txt stays valid; reproduced on macOS by swapping the draws (200 of 200 seeds differ). The test now also prints the first differing line. Refs: #74
The patched OCCT (#74) is in no public cache, so every CI job built it from source: devkit's 15-20 min jobs timed out in their toolchain setup and the Linux kernel job spent 55 min on it. kernel.yml and release-extension.yml now run cachix/cachix-action (pinned, as devkit's ci.yml does) on vars.CACHIX_CACHE: they pull, push what they build when the token is there, and never push from a fork PR. flake.nix names the cache in nixConfig, so local builds pull too. plan.md documents the cache. Refs: #74
On Linux CI the equality test differed on seed 194: s31 against s30. On anvil (x86_64-linux), nixpkgs' UNPATCHED OCCT 7.9.3 gives that same s31, and the patched and unpatched builds agree on all 200 wires: OCCT itself fixes that wire differently under gcc on x86_64 than under clang on aarch64, and the patch changes nothing. So each platform gets its own reference recorded from its own unpatched OCCT (wires-aarch64-darwin.txt from sage, wires-x86_64-linux.txt from anvil); a platform without one fails and says how to record it. Refs: #74
…patched kernel.yml and release-extension.yml gave a same-repo PR the Cachix token and skipPush false, so unreviewed code could push store paths into the cache the releases build from. Only main (push or dispatch) and the release run now get the token; every other run gets none, skipPush true, and a PR step fails if cachix.dhall or CACHIX_AUTH_TOKEN is present. The flake check occt-patch-reference builds occt-patch-check against nixpkgs' unpatched OCCT and requires it to reproduce this platform's wires reference and to fail the scaling test (exponent >= 2.5): the references provably come from unpatched OCCT and the test catches the O(n^3). Pointed at the patched OCCT it fails (2.03). Also: flake.nix drops nixConfig (Lix warns on every eval; plan.md says how to opt in), the seed-194 note no longer claims gcc vs clang, and NOTICE locates the patch in the release's source archive. Refs: #74
gerchowl
force-pushed
the
feature/74-occt-hoist-patch
branch
from
November 8, 2026 15:23
cf90325 to
a7eec1e
Compare
This was referenced Nov 8, 2026
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…64 part 2) (#107) ## #64 part 2: the Quick Look extensions run the kernel out of process Closes #64. Builds on #98 (part 1: the supervisor service), #103 (the kernel reads its descriptor directly) and #91. ### What changes - **No kernel in the extensions.** They link `libstepv_capi.a` only (the renderer and header reader). `otool -L` shows no libstepvocct and no OCCT, and `scripts/test-macos.sh` now checks that. The app's `Frameworks/` serves the CLI's kernel alone. - **Thumbnail:** - The fd goes to the service, which runs the kernel; the extension replies once with the rendered image. - **Deadline 15 s**, enforced by the service, plus a 17 s backstop in the extension. Quick Look's thumbnail watchdog is reportedly about 20 s, and a thumbnail has nothing to show partway, so the kernel gets 15 s and the render and reply get the rest. - **Preview:** - The header shows at once, then the assembly tree (the outline, indented, at most 14 lines) and live progress, then the scene. - **`handler(nil)`:** once the header and tree are on screen. With no tree (IGES, BREP, a failed or oversized outline), on the first mesh or the failure. At the latest **after 20 s** (the watchdog is about 30 s; 10 s of margin). - The view lives on, so the run may take up to **120 s** (the 42 s Ultimaker assembly loads). The run is cancelled when the view goes away. - **Memory cap:** 4096 MB in both, the CLI's default. ### ql-e2e on the real extensions (`just ql-e2e`) Every check reads #113's single `log stream` and matches by identity, never by time: - Each extension logs which run of which service took its file: `accepted: run #N (service pid P), thumbnail|preview <path>`. `scripts/ql-e2e/runs.py` reads that run's own lines and judges by stream order alone. `runs_test.py` checks each verdict on made-up streams first, with a pid-prefix decoy among them. - A preview and a thumbnail for STEP, IGES and BREP. Each preview must be ready exactly once: on its tree before the scene for STEP, on its mesh for IGES and BREP. - A 4000-part file is thumbnailed past its 15 s deadline, with `box.brep` beside it. - At L ≥ 2, box.brep's run is never queued and exits before the held run's kill. - At L = 1, box.brep's run is queued and spawns only after that kill, if at all. - Then the held run's `killed (deadline)`, no thumbnail, its kernel gone, and the next thumbnail under 3 s. - **Closed preview:** the host closes on a signal sent once the file's ready line is in the stream, never at a set time. It logs its close and its quit 3 s later. The kernel's SIGKILL cancel must fall between the two, be reaped within 1 s, and be gone. - **Closed before ready:** Quick Look keeps the controller until its handler is called, so the kernel is cancelled at the preview's ready (20 s at the latest), not at the close (#122). The case closes on the kernel's spawn. The close must come before the ready line, and the cancel after it, before the quit. - **Switched preview:** the host switches the view to `box.brep` once the file is ready. The old kernel must be cancelled between the switch and the quit, and box.brep must be shown. - Quick Look makes a new controller per item; this was measured again: no controller is prepared twice. - For a closed or switched preview, no result line may follow for the file that went, and its handler must complete exactly once. - **A cancelled session** (closed, or superseded by a second prepare: `StepvPreviewSlot`): - Its kernel is killed. - Nothing of it reaches the view: a late tree, progress, result, ready or decode is dropped and logged `stale, dropped`. - Quick Look's handler completes exactly once: `nil` when ready, `CocoaError(.userCancelled)` if cancelled first. It is then released, because it retains the controller. - The supervisor probe and the cache control are unchanged from main. ### Results (head 08eb056; sage, macOS 26.4; rebased on main after #113, #81, #116 and #119) - `just macos-test`: exit 0. That includes the preview-session unit tests, the linkage check and the supervisor probe. - **Linkage check fails closed:** it requires a Mach header and at least one `(compatibility version` line. A text file fails it, and so does `/nonexistent`. The old check passed a text file, because `otool -L` exits 0 on one. - `just ql-e2e` on the product build (L = 4): exit 0, **ALL PASS**. - Deadline: killed at 15 023 ms, reaped in 22.4 ms, gone. - Concurrent: box.brep was never queued and exited before the kill. - No throttle: 112 ms. - Closed: cancelled between the close and the quit, reaped in 17.7 ms. - Switched: the same, reaped in 18.7 ms. - **The same run on an L = 1 test build** (CI's 7 GB case): exit 0, ALL PASS. box.brep was queued and spawned after huge.step's kill (killed at 15 031 ms). - **Without the `deinit` cancel** (mutant): FAILURES. The closed and the switched preview were each cancelled only after the host quit. - **Controller reuse** (round 6, `PreviewSessionTests`): A's result arrives and its decode is still running when B supersedes it. - Passes: A shows nothing and its handler completes once, cancelled. B is ready on its own result, and its handler completes once. - Without the liveness check: exit 1. A's result is shown, and it marks B ready. - Without the handler's release: exit 1. In ql-e2e the closed and the switched previews were then cancelled only at the quit. - cbbe55e's macos-15 CI was red: the closed preview was cancelled only at the quit. The tree had not come by the fixed 8 s close, and the controller lives until its handler is called. Closes and switches are now ordered on the logged ready (08eb056). - Round 6 on 08eb056: `just macos-test` exit 0, `just ql-e2e` exit 0, ALL PASS. Closed before ready: ready (tree) at 4.47 s, then the cancel, reaped in 15.9 ms. - Nits filed: #120 (`.p21`), #121 (a mesh decode error is reported as "no geometry"). Design question: #122 (call the handler sooner?). - `scripts/ql-e2e/supervisor.sh`: exit 0. `cargo fmt --check`: exit 0. `cargo clippy --all-targets -- -D warnings`: exit 0. No kernel change. ### Known limits - #92: multi-file assemblies. - #97: Developer ID and the hardened runtime. - #101: three OCCT copies, +117 MB. - `macos-outer`: the kernel's own Seatbelt profile can't nest inside the service's sandbox. - The watchdog figures are reports, not documented values. The reasoning is in `macos/Shared/StepvKernel.swift` and plan.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs: #74
What
stepv now builds OCCT 7.9.3 with one patch, the corrected hoist from the #74 gate, to
ShapeFix_IntersectionTool::FixSelfIntersectWire. The patch fetchesedge1once pernum1, and fetches it again after the big-segment branch'sRemove(numseg2); Remove(numseg1). Healing a wire of n edges drops from O(n³) to O(n²). The results don't change.flake.nix:occt = pkgs.opencascade-occt.overrideAttrs { patches = [ ./nix/patches/occt-7.9.3-fixselfintersectwire-hoist.patch ]; }. The dev shell (just kernel, the macOS app's dylibs) and the kernel derivation (the product, the Linux tarball,nix flake check) all use it.patchPhase, and an OCCT version other than 7.9.3 fails evaluation.nix/patches/: excluded from the whitespace hooks.Tests
kernel/occt-patch-checkis built beside the kernel with-DSTEPV_BUILD_TESTS=ON, against the same OCCT, andtests/occt_patch.rsruns it:fix_self_intersect_wire_is_quadratic: the growth exponent of the fix time from an 800-gon to a 3200-gon, which is a ratio of CPU times rather than a wall-clock threshold. The threshold is 2.5: the test requires < 2.5.fix_self_intersect_wire_matches_unpatched_occt: 200 generated wires, 91 of which go through the big-segment branch. Each must come out exactly as this platform's reference,tests/occt-patch/wires-{aarch64-darwin,x86_64-linux}.txt, which was recorded with nixpkgs' unpatched OCCT on that platform.checks.<system>.occt-patch-reference: builds the check tool against nixpkgs' unpatchedpkgs.opencascade-occtfrom cache.nixos.org. That build must reproduce the platform's reference byte for byte, and must fail the scaling test (exponent ≥ 2.5). In CI it passes on unpatched OCCT, with 2.940 on aarch64-darwin and 2.880 on x86_64-linux, both ≥ 2.5. Pointed at the patched OCCT (2.03) it fails. Both kernel lanes run it innix flake check.Binary cache
The patched OCCT is in no public cache. It takes about 35 min to build on sage and about 55 min on a GitHub Linux runner.
gerchowl, seeded for aarch64-darwin (from sage) and x86_64-linux (built on anvil, pushed from sage).cachix/cachix-action(pinned v17) inkernel.ymlandrelease-extension.yml.main(a push or a dispatch) and from the release run. A pull request gets no token:authTokenis empty andskipPushis true. The step "A pull request holds no Cachix token" fails the run ifcachix.dhallorCACHIX_AUTH_TOKENis present.ci.ymlstill passes the token on same-repo PRs. This is tracked in security(ci): managed ci.yml passes the Cachix push token to same-repo pull_request runs (cache poisoning) devkit#1881.nixConfig), and token rotation.Evidence
num1range after the removals:NbEdges() >= num1 + dnum1 >= num1, sonum1is always in range and no guard is needed (plan.md "OCCT patch: FixSelfIntersectWire is O(n³) in edges per wire (#51) #74 OCCT patch").just macos-testsupervisor check fails the same way on main (tracked in main red: macos-15 supervisor check 'the slow run's kernel is running' fails after #108 merged #111). On both lanes,occt_patchandocct-patch-referencepass and OCCT is substituted fromgerchowl.cachix.org.