Skip to content

Replace mutable list usages with TreeList in stack operations#1033

Merged
Robotgiggle merged 9 commits into
FallingColors:1.21from
s5bug:vector-fixes-4
Jul 17, 2026
Merged

Replace mutable list usages with TreeList in stack operations#1033
Robotgiggle merged 9 commits into
FallingColors:1.21from
s5bug:vector-fixes-4

Conversation

@s5bug

@s5bug s5bug commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1032

TODO is make a pass through all the list ops and make sure they're not doing O(n) copies but I'm not going to waste my time with that in case I have to go back and modify other stuff

@github-project-automation github-project-automation Bot moved this to 📋 Backlog in Hex Casting Apr 28, 2026
@s5bug
s5bug force-pushed the vector-fixes-4 branch 2 times, most recently from 9ae3fb8 to 2ddfb0a Compare May 10, 2026 19:09
@s5bug
s5bug changed the base branch from main to 1.21 June 7, 2026 20:32
@s5bug
s5bug force-pushed the vector-fixes-4 branch 5 times, most recently from 24b4424 to b7864a8 Compare June 12, 2026 02:00
@s5bug
s5bug marked this pull request as ready for review July 16, 2026 00:11

@Robotgiggle Robotgiggle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I haven't tested exhaustively but nothing seems to be broken. Simulate still works fine, as does the Shepherd Directrix.

Comment thread CHANGELOG.md Outdated

- Removed APIs deprecated in `0.11.4` ([#1126](https://github.com/FallingColors/HexMod/pull/1126), [#1127](https://github.com/FallingColors/HexMod/pull/1127) [#1129](https://github.com/FallingColors/HexMod/pull/1129), [#1137](https://github.com/FallingColors/HexMod/pull/1137), [#1142](https://github.com/FallingColors/HexMod/pull/1142)) @s5bug
- ListIota now uses the asymptotically-efficient TreeList internally ([#1032](https://github.com/FallingColors/HexMod/pull/1032)) @s5bug
- SpellList has been removed, the Casting Image and Casting Frames now store iotas in a TreeList ([#1033](https://github.com/FallingColors/HexMod/pull/1033)) @s5bug

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SpellList was removed in #1032, not here


val image2 = image.withUsedOp().copy(stack = stack)
// FIXME this is expensive if the stack is incredibly large
// someone should rewrite this op to cut and replace a `slice` of the `TreeList` stack

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I have an implementation for this - can I push it to this PR or do you want it in a separate PR after this goes in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Go nuts 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, it's been pushed. Let me know if you think I did anything wrong.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any advantage to having newOrder be a TreeList? Or would it be better to have it also be a standard MutableList?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At such a small size I think it makes almost no difference. If we know the "eventual" size of newOrder then I'd say make it an ArrayList pre-allocated to that size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's an asymptotic fast-path for if the thing being appended is already a treelist:

  • With an arbitrary non-TreeList collection, appendedAll looks like newBuilder.append(this).append(that).build, O(m+n)
  • If either this or that are relatively small enough, the fast path is O(min(m, n))

So, I'd say maybe just leave it a TreeList if we're optimizing for the "people are lagging the server" case, but I don't know 😄 not experienced in that area

@s5bug

s5bug commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

New Swindler's looks good, I just replaced the x = x.addOne with x being a builder instead since the collection isn't used for anything else

@Robotgiggle Robotgiggle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Robotgiggle
Robotgiggle added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@Robotgiggle
Robotgiggle added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@Robotgiggle
Robotgiggle added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@Robotgiggle
Robotgiggle added this pull request to the merge queue Jul 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2026
@Robotgiggle
Robotgiggle enabled auto-merge July 17, 2026 03:48
@Robotgiggle
Robotgiggle added this pull request to the merge queue Jul 17, 2026
Merged via the queue into FallingColors:1.21 with commit 488073c Jul 17, 2026
5 of 8 checks passed
@github-project-automation github-project-automation Bot moved this from 📋 Backlog to ✅ Done in Hex Casting Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants