FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

use lazyregexp to compile regexes on first use by thaJeztah · Pull Request #5998 · docker/cli · GitHub

/ cli Public

use lazyregexp to compile regexes on first use - #5998

Merged
thaJeztah merged 12 commits into
docker:masterfrom
thaJeztah:lazy_regexp
Apr 11, 2025
Merged

use lazyregexp to compile regexes on first use#5998
thaJeztah merged 12 commits into
docker:masterfrom
thaJeztah:lazy_regexp

Conversation

thaJeztah commented Apr 10, 2025
edited
Loading

Copy link
Copy Markdown
Member

implement lazyregexp package based on the "lazyregexp" package in golang.org/x/mod;
https://cs.opensource.google/go/x/mod/+/refs/tags/v0.19.0:internal/lazyregexp/lazyre.go;l=66-78

This package allows defining regular expressions that should not be
compiled until used, but still providing validation to prevent
invalid regular expressions from producing a panic at runtime.

This is largely a copy of the package from golang.org/x/mod,
with FindAllStringSubmatch and ReplaceAllLiteralString,
and ReplaceAllStringFunc added

- What I did

- How I did it

- How to verify it

differences;

  • time: -0.060 ms
  • bytes: -64,880
  • allocs: -583

Before:

GODEBUG=inittrace=1 ./build/docker --version 2>&1 | grep github.com/docker/cli
init github.com/docker/cli/cli/compose/types @2.8 ms, 0.011 ms clock, 672 bytes, 4 allocs
init github.com/docker/cli/cli/compose/template @4.2 ms, 0.062 ms clock, 12472 bytes, 92 allocs
init github.com/docker/cli/internal/tui @4.4 ms, 0.003 ms clock, 448 bytes, 19 allocs
init github.com/docker/cli/templates @5.0 ms, 0.002 ms clock, 672 bytes, 4 allocs
init github.com/docker/cli/cli/config @5.1 ms, 0 ms clock, 16 bytes, 1 allocs
init github.com/docker/cli/opts @5.2 ms, 0.020 ms clock, 18840 bytes, 145 allocs
init github.com/docker/cli/cli/command/formatter @5.2 ms, 0 ms clock, 192 bytes, 2 allocs
init github.com/docker/cli/cli-plugins/hooks @5.3 ms, 0 ms clock, 336 bytes, 2 allocs
init github.com/docker/cli/cli/context/store @5.9 ms, 0.004 ms clock, 3048 bytes, 46 allocs
init github.com/docker/cli/cli/compose/schema @7.6 ms, 0.001 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/compose/loader @7.6 ms, 0.019 ms clock, 4536 bytes, 54 allocs
init github.com/docker/cli/cli-plugins/manager @7.7 ms, 0.023 ms clock, 2648 bytes, 38 allocs
init github.com/docker/cli/cli/command/service/progress @7.8 ms, 0.005 ms clock, 464 bytes, 2 allocs
init github.com/docker/cli/cli/flags @7.8 ms, 0 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/trust @8.1 ms, 0 ms clock, 32 bytes, 2 allocs
init github.com/docker/cli/cli/command @8.9 ms, 0 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/command/context @8.9 ms, 0.004 ms clock, 192 bytes, 2 allocs
init github.com/docker/cli/cli/command/image @8.9 ms, 0.008 ms clock, 3256 bytes, 36 allocs
init github.com/docker/cli/cli/command/container @8.9 ms, 0.048 ms clock, 13488 bytes, 157 allocs
init github.com/docker/cli/cli/command/manifest @8.9 ms, 0.015 ms clock, 2352 bytes, 2 allocs
init github.com/docker/cli/cli/command/node @9.0 ms, 0.014 ms clock, 280 bytes, 2 allocs
init github.com/docker/cli/cli/command/trust @9.0 ms, 0.009 ms clock, 5648 bytes, 86 allocs
init github.com/docker/cli/cli/command/system @9.0 ms, 0.003 ms clock, 1048 bytes, 16 allocs
init github.com/docker/cli/cli/command/stack/swarm @9.0 ms, 0.003 ms clock, 464 bytes, 2 allocs

After:

GODEBUG=inittrace=1 ./build/docker --version 2>&1 | grep github.com/docker/cli
init github.com/docker/cli/cli/compose/types @3.3 ms, 0.014 ms clock, 672 bytes, 4 allocs
init github.com/docker/cli/internal/lazyregexp @6.8 ms, 0 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/compose/template @6.8 ms, 0.009 ms clock, 464 bytes, 4 allocs
init github.com/docker/cli/internal/tui @6.9 ms, 0.008 ms clock, 448 bytes, 19 allocs
init github.com/docker/cli/templates @7.7 ms, 0.013 ms clock, 672 bytes, 4 allocs
init github.com/docker/cli/cli/config @8.0 ms, 0 ms clock, 16 bytes, 1 allocs
init github.com/docker/cli/opts @8.0 ms, 0.006 ms clock, 96 bytes, 2 allocs
init github.com/docker/cli/cli/command/formatter @8.0 ms, 0 ms clock, 192 bytes, 2 allocs
init github.com/docker/cli/cli-plugins/hooks @8.2 ms, 0 ms clock, 336 bytes, 2 allocs
init github.com/docker/cli/cli/context/store @9.4 ms, 0.012 ms clock, 48 bytes, 1 allocs
init github.com/docker/cli/cli/compose/schema @10 ms, 0.010 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/compose/loader @10 ms, 0.020 ms clock, 4536 bytes, 54 allocs
init github.com/docker/cli/cli-plugins/manager @10 ms, 0.006 ms clock, 48 bytes, 1 allocs
init github.com/docker/cli/cli/command/service/progress @10 ms, 0.013 ms clock, 464 bytes, 2 allocs
init github.com/docker/cli/cli/flags @10 ms, 0 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/trust @11 ms, 0.006 ms clock, 32 bytes, 2 allocs
init github.com/docker/cli/cli/command @11 ms, 0.007 ms clock, 0 bytes, 0 allocs
init github.com/docker/cli/cli/command/context @11 ms, 0.005 ms clock, 192 bytes, 2 allocs
init github.com/docker/cli/cli/command/image @11 ms, 0.008 ms clock, 48 bytes, 1 allocs
init github.com/docker/cli/cli/command/container @11 ms, 0.016 ms clock, 3040 bytes, 35 allocs
init github.com/docker/cli/cli/command/manifest @11 ms, 0.015 ms clock, 2352 bytes, 2 allocs
init github.com/docker/cli/cli/command/node @11 ms, 0.026 ms clock, 280 bytes, 2 allocs
init github.com/docker/cli/cli/command/trust @12 ms, 0.006 ms clock, 128 bytes, 4 allocs
init github.com/docker/cli/cli/command/system @12 ms, 0.008 ms clock, 48 bytes, 1 allocs
init github.com/docker/cli/cli/command/stack/swarm @12 ms, 0.008 ms clock, 672 bytes, 3 allocs

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

Based on the "lazyregexp" package in golang.org/x/mod;
https://cs.opensource.google/go/x/mod/+/refs/tags/v0.19.0:internal/lazyregexp/lazyre.go;l=66-78

This package allows defining regular expressions that should not be
compiled until used, but still providing validation to prevent
invalid regular expressions from producing a panic at runtime.

This is largely a copy of the package from golang.org/x/mod,
with FindAllStringSubmatch and ReplaceAllStringFunc added

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This package needed an (internal) interface to abstract the lazy-regexp.
For this, I split the implementation from the exported implementation; this
also revealed that some functions are not used (at least not in our code
base), and we could consider deprecating these.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Apr 10, 2025
thaJeztah added this to the 28.1.0 milestone Apr 10, 2025

codecov-commenter commented Apr 10, 2025
edited
Loading

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 53.84615% with 24 lines in your changes missing coverage. Please review.

Project coverage is 59.06%. Comparing base (bcd9c88) to head (4c820d3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5998      +/-   ##
==========================================
- Coverage   59.09%   59.06%   -0.04%     
==========================================
  Files         355      356       +1     
  Lines       29751    29792      +41     
==========================================
+ Hits        17582    17597      +15     
- Misses      11193    11219      +26     
  Partials      976      976              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

thaJeztah merged commit e578f15 into docker:master Apr 11, 2025
thaJeztah deleted the lazy_regexp branch April 11, 2025 10:29
thaJeztah self-assigned this May 16, 2025
This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL