Repository navigation
Avoid repeated full-band copies when building raster grids - #1256
Open
AlexisDrogoul wants to merge 1 commit into
Open
AlexisDrogoul wants to merge 1 commit into
AlexisDrogoul wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused optimization preserves existing indexing behavior while removing the repeated band-copy overhead.
0 open findings
What changed in this PR
Caches raster bands once during multi-band grid construction, eliminating repeated full-band copies.
Changes:
- Loads each band once before iterating over cells.
- Reuses cached arrays when populating per-cell band values.
| File | Description |
|---|---|
gama.core/src/gama/core/topology/grid/GamaSpatialMatrix.java |
Optimizes multi-band raster grid initialization. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cache each raster band once while constructing a multi-band
GamaSpatialMatrix.GamaGridFile.getBand()copies the full band array, so retrieving it inside the per-cell loop made initialization copy each band once per cell (O(bands × cells²)). The new code performs one copy per band and reuses those arrays while populating cells (O(bands × cells)).Ten performance opportunities identified
GamaSpatialMatrix.valueOfand coordinate transform per raster per cell.fastDiffusionWithConvolution's vector loop.ArrayListper output cell and coordinate arrays per contributing neighbor.diffusionWithDotProduct.Integer/ArrayListallocation per radius and correct the undersized perimeter list capacity.ArrayListqueue entries and boxed costs with a typed priority-queue entry.The other items are source-level candidates for follow-up; they were not benchmarked as part of this change.
Validation
gama.corecompiled successfully in the full Maven reactor. The full reactor later failed while resolvinggama.feature.extensionsbecause the localgama.devp2 unit version was unavailable.git diff --checkpassed.