uap-go icon indicating copy to clipboard operation
uap-go copied to clipboard

Optimize for top-user-agents

Open dzbarsky opened this issue 3 years ago • 2 comments

Teaches the build script to clone top UAs and optimize the matching order accordingly. This leads to huge speedups in real-world (browser) usage.

dzbarsky avatar Dec 29 '20 03:12 dzbarsky

I'm not against optimization, but this makes the implementation more complicated - do you have any numbers to justify this change? I'd really love a current team/person depending on this library to weigh in..

elsigh avatar Jan 17 '21 17:01 elsigh

I don't think it makes the implementation more complicated - all it does is reorder the list of regexes we test against. In fact, the library implementation is exactly the same. The diff looks big because my editor ran gofmt and removed oddities like trailing semicolons, etc.

As for numbers, I believe I saw around 100x+ speedup on UA parsing, with this change UA parsing disappears from profiles. Intuitively, it makes sense that testing the conditions that are likeliest to match upfront will result in better performance.

dzbarsky avatar Mar 06 '22 19:03 dzbarsky