Urgent.News

What's breaking now, across thousands of outlets.

Tech

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.

Read the original at dev.to →

More in Tech

Why do we use primary keywords and hashtags in content creation and digital marketing?

Primary keyword This is the main phrase a page is built around, the thing you want it to rank for on Google. A write-up on your site might target “TryCloudflare phishing detection.” Why it matters…

  • Primary keywords centralize a page's focus to rank for specific search terms.
  • Hashtags categorize content on social media, expanding post reach and engagement.
  • Overuse of keywords or hashtags can negatively impact rankings and appear spammy.

Roughly organizing entities, value objects, services, and use cases.

Well, it's related to Rails, DDD (Domain-Driven Design), and Clean Architecture. Here is a list of terms: - Entities: things identified by ID - Examples: User, Case, Order - Value Objects: things…

  • Entities are core objects identified by unique IDs in Ruby on Rails.
  • Value objects are defined by attributes, not identity, like a ¥1000 note.
  • Service objects encapsulate specific actions, orchestrating entities and value objects.

More from Saturday 31 October →