I Optimized a Button From O(n) to O(1). The Speed Didn't Matter.
A bug report, a route map, and three rounds of making it faster — a story about what Big O really measures, why constants win at small n, and why the best algorithm is sometimes deleting the question. The bug report was one line long: "Audit logs from the Users page show nothing." I opened the Users list, clicked Audit logs , and landed here: /audit-logs?type=Users&ResourceId=users…
A bug report was received: audit logs from the Users page showed nothing. The Users list contains a button that triggered a search for an id from the URL. The button was present on multiple pages of the admin panel and took no props. The button used a map to search route prefixes to log types. The button's code was found to have a linear search, which had a time complexity of O(n).
The author wanted to make the button faster, so they started thinking in Big O notation and tried to optimize the search. However, they discovered that the input size was small and fixed, so the linear search was not a significant issue. The author then tried to optimize the button by using a hash map, which would have an average time complexity of O(1).
However, they found that the new implementation was actually slower than the original one, even though it had a better time complexity. The author concluded that the best algorithm is sometimes deleting the question, rather than finding a perfect solution.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.