A few days ago, an article by Flutter developer Hammad Tariq caught my eye: "Rendering 10,000 Machine State Changes on a Timeline Without Freezing Flutter".
It was a solid piece of profiling detective work. Hammad was building a high-density timeline view in Flutter representing 10,000 machine state transitions. But every time the dataset loaded, the mobile UI stuttered and dropped dozens of frames.
Under a section aptly titled "The Original Sin", the author identified the culprit:
sorted.sort((a, b) => DateTime.parse(a.start).compareTo(DateTime.parse(b.start)));
Because sorting makes O(N log N) comparisons, sorting 10,000 items was triggering over 215,000 redundant calls to DateTime.parse() right inside the comparison callback, blowing past the 16ms frame budget and freezing the screen.
To fix the frame freeze, Hammad introduced a clever optimization: map each item to a temporary helper object holding the pre-computed timestamp, sort the list using that cached value, and unwrap it: