3 ms·
Using a linked-list where the actual access pattern is random and an hash table is more suitable would be the most obvious, especially since this is C code. Si
by acveilleux 11y ago
Using a linked-list where the actual access pattern is random and an hash table is more suitable would be the most obvious, especially since this is C code.
Similar things includes C-style string functions like strlen() and so on that require iterating over an unknown length array. Caching (or better avoiding!) this work can save a lot of computing time. Example from libgit2: https://github.com/libgit2/libgit2/commit/7132150ddf7a883c1f12a89c2518c1a07c0dc94c https://github.com/libgit2/libgit2/commit/7132150ddf7a883c1f...
In fact C-style string is a rich source of O(n) performance issues. And git is full of strings like filenames.
- cmrx64 11y agoTo me, I would have called that an "O(n^2)" (or whatever the proper non-linear order is) issue. The issue isn't that the algorithm is O(n), but that it's not O(n) when it could be! The other interpretations by andrewaylett and daveguy seem to be more accurate (and also agrees with my own thinking). But I could also see it being used for "the asymptotic complexity was hiding a huge constant". Have you heard your interpretation used in the wild?