git: Replace regexp in ValidateHex
In cases where very large numbers of OIDs are parsed by Gitaly, the
regular expression used in git.ValidateHex
can become extremely
expensive.
Fortunately this is not a common scenario, but it's still worth using more efficient but slightly more complex code to validate OIDs to prevent this from happening.
This was quite noticeable when running RepositorySize
with the catfile_repo_size
feature flag against the Chromium repo. See flamegraph below:
Edited by Will Chandler (ex-GitLab)