Skip to content

Curve add-ons: tối ưu hiệu năng, snap NURBS, kéo grip, giới hạn Helix/Spiral - #4

Open
vn-Jay3Designer wants to merge 8 commits into
MYuitsu:mainfrom
vn-Jay3Designer:codex/curves-next
Open

vn-Jay3Designer wants to merge 8 commits into
MYuitsu:mainfrom
vn-Jay3Designer:codex/curves-next

Conversation

@vn-Jay3Designer

Copy link
Copy Markdown
Collaborator

Tóm tắt

PR này tiếp nối PR #3. Nội dung chính: xử lý việc lệnh add-on chậm hơn lệnh tích hợp (số đo admin: Line 2,371 ms so với 0,308 ms), bổ sung snap cho đường cong NURBS, sửa thao tác kéo grip và giới hạn số vòng/số điểm cho Helix/Spiral.

Hiệu năng add-on

Nguyên nhân chậm không phải JSON (mã hóa/giải mã và chạy add-on chỉ ~0,03 ms/bước) mà do host làm việc thừa ở mỗi bước:

  • Mỗi bước resolve và sao chép cả 453 settings của gói Matrix → host có bảng tra settings theo lệnh (Host::command_settings, command_info).
  • Mỗi bước duyệt toàn bộ scene → bỏ qua khi không chọn gì; khi có chọn thì tra qua bảng SceneRoots (dựng một lần mỗi scene).
  • Kết quả một vật mới phải dựng lại cả scene → dùng commit_incremental_scene như lệnh tích hợp.

Release, trung vị 40 mẫu, chạy xen kẽ, có kiểm hình và đúng 1 mục Undo (crates/om9-app/tests/addon_bench.rs):

Tích hợp Add-on trước Add-on sau
Line 10 mm, document rỗng 0,093 ms 2,106 ms 0,106 ms
Circle r5, document rỗng 0,083 ms 2,148 ms 0,101 ms
Rê chuột trong lệnh – 0,40 ms 0,02 ms
Line, 20.000 vật ~220 ms 268,7 ms 223,3 ms
Offset có chọn vật, rê chuột, 20.000 vật – 0,228 ms 0,060 ms

Snap

  • Snap giao điểm trước đây thử mọi cặp đoạn trong cả file mỗi lần rê chuột (20.000 đường: 581 ms) → chỉ xét các đoạn gần con trỏ (19,8 ms, số điểm snap không đổi).
  • Đường cong NURBS trước đây không có snap nào → End (gồm mọi đỉnh polyline), Mid, Near, Perpendicular, Intersection; có bước loại sớm theo hộp bao điểm điều khiển.

Kéo grip (4 test trong ui::chrome đang lỗi trên main → đều đạt)

  • Bấm vào grip không còn bị tay cầm gumball đè lên chiếm thao tác.
  • Khung thả chuột cập nhật đúng vị trí con trỏ/snap.
  • Không snap Near/Perpendicular/Tangent/Surface vào chính vật đang sửa (End/Mid vẫn dùng được, ví dụ để khép kín đường cong).
  • Test mới: control_grip_drag_snaps_to_an_end_of_its_own_curve.

Helix/Spiral

Kiểm tra số vòng (tối đa 1000) và số điểm dự kiến (tối đa 20.000, ước lượng theo bán kính và dung sai 0,0005 mm) trước cả preview lẫn lúc tạo hình. Vượt giới hạn thì báo lỗi kèm hướng dẫn: tăng Pitch / giảm chiều dài trục (hoặc giảm Turns).

Khác

  • physical_memory đọc /proc/meminfo trên Linux (trước đây Controller::new lỗi trên mọi máy không phải Windows).
  • Tạo lại tài liệu gói Matrix theo vị trí menu Solid mới trên main (package_files_match_the_menu_crates).
  • Skill openmatrix9-feature-port: thêm quy tắc ưu tiên lệnh tích hợp và checklist hiệu năng cho add-on.
  • Hồ sơ đo: docs/validation/2026-11-05-addon-performance.md.

Kiểm thử

  • Add-on: curves 41, curve_tools, matrix package, host om9-addons.
  • om9-app: addon_session, addon_command, addon_smoke, addon_bench, grip_selection; thư viện 381 đạt. 5 test lỗi đã lỗi sẵn trên main khi chạy trên Linux (LOCALAPPDATA, không có OCCT, catalog gợi ý lệnh).
  • om9-scene (gồm test snap mới), om9-native-owner, tools/public_source_audit.py 0 lỗi.
  • CI Windows trên fork: đạt.

Việc còn lại (phần lõi)

Trong file lớn, thêm 1 vật vẫn mất ~45–55 ms ở 5.000 vật và ~220–300 ms ở 20.000 vật, lệnh tích hợp cũng như add-on. Phân bổ: register_prepared_document ~46%, prepare_with_held_usage ~18%, coordinator.commit ~17%.

Records the 2026-11-05 benchmark (built-in Line/Circle ~7.7-9.3x faster
than the add-on through the JSON ABI, release headless, empty document)
and the rule: add-ons only add what OM9 lacks; measure before an add-on
replaces an existing command; follow the admin's built-in choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
Before anything is sampled (preview and final shape alike), the command
now estimates the points the curve needs: turns × points per turn, where
points per turn ≈ 2.4·(radius/tolerance)^¼ (measured; nearly independent
of the pitch, the larger radius for a spiral). Past 1000 turns or 20000
expected points it refuses and says what to change: "increase Pitch or
reduce the axis length" (or "reduce Turns" when Turns was typed). The
preview is checked against the final limits, so it never shows a shape
that will be refused. The estimate also seeds the fit, so fewer passes.

Test: radius 50 with 600 turns is refused at once (preview and finish),
with the right advice for Pitch and for Turns, while 100 turns of radius
50 is made within 0.001 mm; spirals are checked by their larger radius.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
package_files_match_the_menu_crates failed on main after the PR MYuitsu#3
integration; regenerated with OM9_UPDATE_PACKAGE=1 (menu slot numbers only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
Each interactive step resolved and copied the whole settings table of the
package (453 specs in OM9 Matrix): ~0.38 of 0.41 ms per step. Host gains
command_settings(id, command) and command_info filters first (same
resolution). Selection/transform walks return at once when there is
nothing to walk; a single new object is committed incrementally, as the
built-in Line/Circle do.

Release, medians of 40 (addon_bench): Line 2.106 -> 0.106 ms (built-in
0.093), Circle 2.148 -> 0.101 ms, hover 0.40 -> 0.02 ms; 5,000/20,000
objects now equal to built-in. Linux: physical_memory reads /proc/meminfo
(Controller::new failed off Windows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
- NURBS curves had no object snaps; they now give End (ends and polyline
  vertices), Mid, Near, Perpendicular and Intersection, culled by the
  control-hull box.
- Intersection paired every segment of the file on each pointer move
  (20,000 lines: 581 ms); only segments within the snap radius can form a
  candidate, so only those are paired (19.8 ms, same candidates).
- Grip drag: a grip under the press wins over a crossing gumball handle;
  the release frame takes the released pointer/snap; along-object snaps
  on the edited object are ignored (End/Mid still apply). The four
  failing chrome grip tests pass; new end-snap grip test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
- Host keeps, per installed add-on, which settings apply to each command
  (built once from the manifest); command_settings/command_info no longer
  scan the whole package table, so the cost does not grow with more menus.
- Add-on steps find the picked objects through an object -> scene position
  table built once per published scene (validated, rebuilt on change)
  instead of walking every scene object on each click and pointer move.

Offset on one picked line, pointer move: 20,000 objects 0.228 -> 0.060 ms
(flat from 1 to 20,000 objects). New tests: selection after scene changes;
bench_edit_command_with_selection (ignored).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AChfY1X8M1iXCrsZMoDud
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