Commit 5cbd14a
perf: share RowGroup instances across ScenarioData snapshots
RowGroup is effectively immutable — all fourteen fields are declared
final and no caller mutates the lists returned by its getters (getRows()
even wraps its internal list in Collections.unmodifiableList()). The
deep-copy loop in RowGroupSequence that called new RowGroup(rg) for
every element was therefore pure waste: for a scenario-heavy sequence
it could produce thousands of unnecessary RowGroup objects and four
times as many ArrayList allocations per layout pass.
Replace the per-element copy loop with new ArrayList<>(template.group),
which copies the list container (so independent add() calls on one
snapshot do not affect another) while sharing the RowGroup element
objects. Add a null guard to match the behaviour of the non-deepMode
path.
Remove the now-unreachable RowGroup(RowGroup template) copy constructor
to prevent future confusion.
Note: the blocks list is intentionally still shallow-copied in deepMode.
ScenarioData.getBlocks().add() mutates it after snapshots are taken, so
sharing it would corrupt saved states (confirmed by three integration
test failures during development).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 9983d7b commit 5cbd14a
2 files changed
Lines changed: 4 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | 174 | | |
199 | 175 | | |
200 | 176 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
0 commit comments