Open ekwoka opened 2 months ago
while I don't necessarily disagree with some of the formatting changes in here, wouldn't it be best to remove them for now to make the PR easier to review?
Sure. I think there's like 2 or 3 that just got caught up in the mix. They're quite separate from the main code so it shouldn't be too much noise though. When I get the test in, I can correct some of those.
Thanks for all your work on this! Any estimate when it might be merged in?
This also solves #4192 #4157 related to using
x-sort
withx-for
.The core issue is that x-for never checks if any elements have moved, due to how it is optimized.
See in playground
I looked at just solving that directly, but it would definitely just increase work and increase code.
I identified that, if we want to just always ensure we put the elements in the right place, then we could also massively simplify the logic while maintaining the vast majority of the behavior and optimizations, while solving this initial problem.
Note: As I worked through this, I was quite impressed with how optimized Alpine actually was in the first place. It wasn't a joke when you said it was complexity with a purpose. I was quite worried I'd end up in a situation where the code logic was uglier, longer, slower, and there were times when the old version was doing way better at things I wasn't sure how to handle effectively. Had to do a lot of profiling to find the simplest fixes. Wrote a blog post about the steps, process, logic.
I think I got there. Smaller, faster, and I think many would agree clearer logic.
Synthetic Benchmarks
Some synthetic benchmarks that isolated just the x-for logic. This number includes the browser repaint/reflow, not purely logical gains. For most, the repaint/reflow is the same/similar for both.
JS Framework Benchmarks
Extra Huge Lists
For fun.