Improve performance on year2025::day09 #19
Merged
+48
−53
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.
Both part 1 and part 2 require the input to be sorted, but currently they're sorted independently and in a different order.
Transposing part 1 to work with an input sorted by y first to match part 2 allows you to sort the tiles only once and avoid a couple copies.
Also, using
u32s in place ofu64s where possible makes things a touch faster.Overall, this makes the solution ~15% faster on my machine (M2 Max)
Does it make more sense to refactor part 2 to work with x-ordered tiles?EDIT: Part 2 is twice as fast with the x-ordered (transposed) processing order due to the structure of the input, so sorting by
(y, x)instead of(x, y)makes sense.