-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ociregistry: deduplicate and lazily compile global regexes
cmd/cue imports the ociregistry and ociregistry/ociref packages, which cost about 0.1ms and 0.04ms at init time respectively, due to how they compile a few regular expressions at init time. First, two of these are duplicates; ociregistry.IsValidRepoName can be replaced by ociref.IsValidRepository, and ociregistry.IsValidTag can be replaced by ociref.IsValidTag. In both cases, ociref's regular expressions are better documented. Second, ociregistry.IsValidDigest is not a duplicate, but it seems to belong to ociref alongside all the other IsValid funcs, plus ociref already performs similar validity checks in existing APIs. To not break users with the changes above, keep the ociregistry APIs as deprecated funcs which call the ociref APIs. Note that this required reversing the import between the two packages, which was easy enough given ociref only needed ociregistry.Digest, and which seems like the better option given that ociref is lower level. Third, hide the three global regexp.MustCompile calls in ociref behind sync.OnceValue, meaning that the regular expressions only get compiled when they are first used. With all of the changes combined, we save about 0.15ms and 2300 allocs at init time, which should be small but noticeable for cmd/cue. goos: linux goarch: amd64 cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics │ old │ new │ │ sec/op │ sec/op vs base │ CuelabsDevGoOciOciregistry 108690.0n ± 5% 103.0n ± 73% -99.91% (p=0.002 n=6) CuelabsDevGoOciOciregistryOciref 46316.50n ± 4% 19.00n ± 195% -99.96% (p=0.002 n=6) geomean 70.95µ 44.24n -99.94% │ old │ new │ │ B/op │ B/op vs base │ CuelabsDevGoOciOciregistry 130259.0 ± 0% 947.5 ± 0% -99.27% (p=0.002 n=6) CuelabsDevGoOciOciregistryOciref 61912.0 ± 0% 480.0 ± 0% -99.22% (p=0.002 n=6) geomean 87.70Ki 674.4 -99.25% │ old │ new │ │ allocs/op │ allocs/op vs base │ CuelabsDevGoOciOciregistry 1855.000 ± 0% 2.000 ± 0% -99.89% (p=0.002 n=6) CuelabsDevGoOciOciregistryOciref 442.00 ± 0% 21.00 ± 0% -95.25% (p=0.002 n=6) geomean 905.5 6.481 -99.28% Signed-off-by: Daniel Martí <[email protected]> Change-Id: I1be320904649374f768d392c7a104cd2f3c5021e Reviewed-on: https://review.gerrithub.io/c/cue-labs/oci/+/1198992 TryBot-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
- Loading branch information
Showing
7 changed files
with
65 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters