-
Notifications
You must be signed in to change notification settings - Fork 1
perf: replace Mutex<bool> with AtomicBool for has_color tracking #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replace Mutex<bool> with AtomicBool in convert_pointcloud function - Use Arc<AtomicBool> in convert_pointclouds for shared access across threads - Use relaxed memory ordering for simple flag tracking - Reduces lock contention and improves parallel processing performance
WalkthroughReplaces per-thread Mutex color tracking with a shared Arc in the parallel path and a plain bool in the single-thread path. Updates LAS writer invocation accordingly. Keeps Mutex for max_cartesian. Simplifies output path construction and adjusts imports. No public API changes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Converter as convert_pointclouds
participant Threads as Worker Threads
participant AtomicFlag as Arc<AtomicBool> (has_color)
participant MutexMax as Mutex(max_cartesian)
participant Writer as LAS Writer
User->>Converter: Start batch conversion
Converter->>AtomicFlag: Initialize (false)
Converter->>Threads: Spawn workers per chunk
par For each point
Threads->>Threads: Process point
alt Point has color
Threads->>AtomicFlag: store(true, Relaxed)
end
Threads->>MutexMax: lock/update max_cartesian
end
Threads-->>Converter: Join
Converter->>AtomicFlag: load(Relaxed)
Converter->>Writer: write_las(has_color, max_cartesian, output_path)
Writer-->>User: LAS file(s) created
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
* main: chore: format refactor: replace unwrap() calls with proper error handling fix: invalid ref handling refactor: BTreeMap instead of HashMap docs: fix documentation examples in convert_pointcloud refactor: replace indexing with iterators in save_stations refactor: replace &String with &Path in convert_pointcloud APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
src/convert_pointcloud.rs (6)
57-64
: Plain bool for single-thread path: LGTM; small branchless nitUsing a plain bool removes unnecessary locking. You can make the assignment branchless.
- if point.color.is_some() { - has_color = true; - } + has_color |= point.color.is_some();
79-81
: Tiny path-format simplificationUse a single format call for the filename.
- let path = create_path(output_path.join("las").join(format!("{}{}", index, ".las"))) + let path = create_path(output_path.join("las").join(format!("{index}.las")))
137-138
: Shared Arc for parallel color detection: LGTMMinor style nit: Default is a touch shorter.
- let has_color = Arc::new(AtomicBool::new(false)); + let has_color = Arc::new(AtomicBool::default());
156-157
: Cut atomic traffic inside hot loopAccumulate locally and do a single store per shard to reduce contention on busy, colored datasets.
- for p in pointcloud_reader { + let mut local_has_color = false; + for p in pointcloud_reader { let point = p.context("Could not read point: ")?; - if point.color.is_some() { - has_color.store(true, Ordering::Relaxed); - } + if point.color.is_some() { + local_has_color = true; + } … - } + } + if local_has_color { + has_color.store(true, Ordering::Relaxed); + }
183-185
: Repeat path-format nitSame simplification as above.
- let path = create_path(output_path.join("las").join(format!("{}{}", 0, ".las"))) + let path = create_path(output_path.join("las").join(format!("{0}.las")))
194-195
: Relaxed load is fine; add a short rationale commentGiven read happens after the rayon barrier and the flag only flips to true, Relaxed is reasonable. Add a comment to document this assumption.
- has_color.load(Ordering::Relaxed), + has_color.load(Ordering::Relaxed), // safe: read after parallel join; monotonic flag
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/convert_pointcloud.rs
(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/convert_pointcloud.rs (2)
src/utils.rs (1)
create_path
(4-18)src/get_las_writer.rs (1)
get_las_writer
(21-49)
🔇 Additional comments (2)
src/convert_pointcloud.rs (2)
4-5
: AtomicBool + Arc imports look correctGood switch to lock-free flagging; Mutex is still needed elsewhere.
29-29
: No-op doc changeNothing to review here.
Summary
Mutex<bool>
withAtomicBool
for better performance in concurrent scenariosChanges
AtomicBool
directly instead ofMutex<bool>
Arc<AtomicBool>
for thread-safe sharingOrdering::Relaxed
for simple flag tracking operationsPerformance Benefits
Test Plan
Summary by CodeRabbit