Skip to content

Reduce GPU load of selection scan - #356

Open
nabeya11 wants to merge 2 commits into
masterfrom
perf/scan-cache
Open

Reduce GPU load of selection scan#356
nabeya11 wants to merge 2 commits into
masterfrom
perf/scan-cache

Conversation

@nabeya11

@nabeya11 nabeya11 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Problem

scanSelection runs a transform-feedback pass over all points and reads the result back from the GPU on every click, Delete, label key, and console command. On large clouds this wait occurs on every operation. In addition, the Alt/Ctrl click paths ran the same scan twice.

Changes

  • Cache the scan result. The scan output depends only on the point cloud, the crop/select/view/projection matrices, and the cursor position, so the scan is skipped while none of them change. Matrices are compared by value; the cloud and the mask are tracked by new revision counters (updates are funneled through setPointCloudUpdated() to prevent missed invalidations). Only the click path uses the cursor-dependent bit, so it alone requires an exact (x, y) match (needNearCursor).
  • Remove the duplicated scan on Alt/Ctrl click. The result of the scan at the beginning of the click handler is still valid there.
  • Poll the GPU fence with exponential backoff (1→2→…→10ms) instead of the previous flat 10ms interval.

A missed invalidation would silently apply an edit with a stale selection, so the cache can be disabled at runtime with the new scan_cache 0 console command.

- Cache the GPGPU selection scan result keyed by matrices and revision
  counters, skipping redundant full-cloud transform feedback passes and
  4B/point readbacks. Add scan_cache console command as a kill switch.
- Remove duplicated scanSelection calls on Alt/Ctrl click.
- Poll the GPU fence with exponential backoff starting at 1ms instead of
  a flat 10ms interval.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.74419% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.91%. Comparing base (009b647) to head (5b4ca1e).

Files with missing lines Patch % Lines
command.go 74.19% 8 Missing ⚠️
console.go 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #356      +/-   ##
==========================================
+ Coverage   38.96%   39.91%   +0.94%     
==========================================
  Files           8        8              
  Lines        1414     1443      +29     
==========================================
+ Hits          551      576      +25     
- Misses        827      831       +4     
  Partials       36       36              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces the latency and GPU/CPU overhead of selection-related operations by avoiding redundant selection scans, reusing prior scan results when inputs are unchanged, and improving GPU fence polling behavior.

Changes:

  • Adds a selection scan cache keyed by cursor position (when needed), relevant matrices, and new revision counters for point cloud / selection-mask state.
  • Removes a duplicated selection scan in the Alt/Ctrl click paths by reusing the click’s initial scan result.
  • Changes GPU fence polling to use exponential backoff instead of a fixed sleep interval.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
main_js.go Adds scan-result caching, removes duplicate scan on Alt/Ctrl click, and updates fence polling behavior.
console.go Adds a scan_cache console command to toggle the scan cache at runtime.
command.go Introduces revision counters and cache-enable state to support reliable scan-cache invalidation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main_js.go
The doubling was applied after the cap check, so the wait could grow to
16ms. Add tests for the scan_cache command and revision counters.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

command.go:680

  • Undo() bumps pointCloudRev (via setPointCloudUpdated()) even when there is nothing to undo. This unnecessarily invalidates the selection-scan cache and forces point cloud re-uploads/rerenders despite no state change. Bump the revision only when editor.Undo() actually succeeds.
func (c *commandContext) Undo() bool {
	c.setPointCloudUpdated()
	return c.editor.Undo()
}

@nabeya11
nabeya11 requested a review from at-wat August 6, 2026 03:18
@nabeya11
nabeya11 marked this pull request as ready for review August 6, 2026 03:18
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