git-urls
git-urls copied to clipboard
Speed up
Per @anachronistic:
so - i did a couple of benchmarks on the lib and found differing speeds + heap allocations depending on the incoming string and i believe that it's possible to 1) normalize the speed to within reason (i.e. longer strings will naturally take a bit longer to parse), 2) normalize the allocations (i believe you can produce a 0 allocation lib if you write the parser yourself) i did a shit proof of concept and for local paths i had it down to 150ns / 0 allocations by having a
Parsemethod that accepts a pointer to anet.URLstructure ... exfunc Parse(url string, handle *net.URL) error { ... }that was leaning mostly onstrings.Indexwhich reports first appearance of a pattern, so ex.colon := strings.Index(url, ":") ... slash := strings.Index(url, "/") ... return colon == -1 || (slash & slash > colon)sofile:///whateverand/foo/bar/whateverreturnedtruevery quickly it gets a touch more complicated from there, but yeah: that's my challenge to you ... normalized speed (for some reasonable definition of normalized compared to string length) and 0 allocations (or at most 1 if you don't like the C-style of passing in the structure)