Skip to content

perf(native): use index queues for AX BFS#485

Closed
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-ax-bfs-index-queue
Closed

perf(native): use index queues for AX BFS#485
JustYannicc wants to merge 1 commit into
SuperCmdLabs:mainfrom
JustYannicc:codex/perf-ax-bfs-index-queue

Conversation

@JustYannicc

Copy link
Copy Markdown
Collaborator

What changed

  • Replaced Array.removeFirst() queue consumption in the native Accessibility BFS loops with monotonic index cursors.
  • Added scripts/bench-ax-bfs-queue.swift so the queue behavior benchmark is repeatable.

Why

Accessibility selected-text and caret lookup run on hot paths. Array.removeFirst() shifts/copies the remaining queue on every pop, even though these traversals only need FIFO order and already cap depth/element counts.

Behavior and compatibility

  • Preserves BFS search order, focused-child preference, depth limits, and selected/caret lookup fallback order.
  • No user-facing strings changed.

Evidence

  • Baseline before editing, synthetic Swift BFS queue benchmark: removeFirst: 235.47 ms, cursor: 37.95 ms, equal checksum, 6.20x speedup.
  • Repeatable benchmark after change: swift -O scripts/bench-ax-bfs-queue.swift -> removeFirst: 211.29 ms, cursor: 36.80 ms, equal checksum, 5.74x speedup.
  • LSP diagnostics: no errors for src/native/ax-caret-query.swift, src/native/get-selected-text.swift, and scripts/bench-ax-bfs-queue.swift.
  • swiftc -O -o /tmp/supercmd-get-selected-text-check src/native/get-selected-text.swift -framework Foundation -framework ApplicationServices -framework AppKit.
  • swiftc -O -o /tmp/supercmd-emoji-trigger-monitor-check src/native/emoji-trigger-monitor.swift src/native/ax-caret-query.swift -framework AppKit -framework ApplicationServices.
  • node --test 'scripts/test-*.mjs' passed: 24 passed, 1 skipped.
  • node scripts/check-i18n.mjs exited 0; it reports pre-existing Italian locale gaps unrelated to this native-only change.

Risk

Low. The traversal queue still appends in the same order and stops at the same caps; the only intentional change is avoiding per-pop array shifting.

@JustYannicc JustYannicc changed the title [codex] use index queues for AX BFS perf(native): use index queues for AX BFS Jul 3, 2026
@JustYannicc

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated upstream PR #534 (perf(mac): reduce native polling and async IO stalls), which carries this change together with the related macOS/native/audio/camera async IO performance fixes. Closing this source PR so review can continue on #534.

@JustYannicc JustYannicc closed this Jul 3, 2026
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.

1 participant