Use Arc<Ground> for WorldEditor ground reference#690
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the WorldEditor to use Arc<Ground> instead of Option<Box<Ground>> for the ground reference, eliminating unnecessary cloning of potentially large terrain elevation data. The change improves memory efficiency by enabling shared ownership of the Ground struct across multiple parts of the generation pipeline.
- Replaced
Box<Ground>withArc<Ground>for efficient shared ownership - Updated
set_groundAPI to acceptArc<Ground>directly instead of cloning from a reference - Simplified
get_groundimplementation usingas_deref()
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/world_editor/mod.rs | Changed ground field type to Arc<Ground>, updated setter to accept Arc directly, and simplified getter using as_deref() |
| src/data_processing.rs | Wrapped ground in Arc::new(), passed cloned Arc to editor, and used as_ref() for function calls expecting &Ground |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
⏱️ Benchmark run finished in 0m 30s 📈 Compared against baseline: 30s 🟢 Generation time is unchanged. 📅 Last benchmark: 2026-01-06 14:45:12 UTC You can retrigger the benchmark by commenting |
Motivation
Grounddata when storing it inWorldEditorby sharing ownership withArc.Description
WorldEditor::groundfromOption<Box<Ground>>toOption<Arc<Ground>>and adduse std::sync::Arc.set_groundto acceptArc<Ground>and store it directly, and updateget_groundto returnOption<&Ground>usingas_deref().generate_world_with_optionswrap the providedGroundinArc::new(ground)and passArc::clone(&ground)toWorldEditor::set_ground, and update callers to useground.as_ref()where a&Groundis required.use std::sync::Arcimports and adjust call sites insrc/data_processing.rsto match the new API.Testing
Codex Task