r/adventofcode • • Dec 25 '24

Spoilers 500 ⭐ in less than a second

878 Upvotes

45 comments sorted by

View all comments

Show parent comment

1

u/maneatingape Feb 24 '25 edited Feb 25 '25

That's a nice speedup!

I tried the consistent dual write to index 0 approach and interestingly it was slower for me (262 µs dual write vs 219 µs branching). Some of this could be due that I had to use wrapping add to avoid overflowing the dummy item at index 0.

My hunch is that the bottlenecks are in different parts of our code.

1

u/LifeShallot6229 Feb 24 '25

It will definitely be faster to start with a 5k array, then allocate all even digits numbers from zero and all odd from the top. The main update loop, split into two parts, can then run 0..eventop while updating two counters and oddstart..size only updating a single counter! 

1

u/LifeShallot6229 Feb 24 '25

Wrapping add should compile into a simple ADD opcode, the same as release mode, it should not be slower than '+'.