Memoize file match patterns by swiedenfeld · Pull Request #1412 · docker-java/docker-java
Repository navigation
Memoize file match patterns - #1412
Merged
bsideup merged 2 commits into docker-java:master from swiedenfeld:compile_less_patterns Jun 25, 2020
Merged
Memoize file match patterns #1412 bsideup merged 2 commits into docker-java:master from swiedenfeld:compile_less_patterns
Conversation
swiedenfeld commented Jun 12, 2020
Copy link Copy Markdown
Contributor
I ran a profiler to analyse performance of ScannedResult # addFilesInDirectory in the scenario described in #1409 . All ignore strings must be matched on each of the +60k files, and a not neglible amount of time is spent compiling the Strings from ignores into patterns over and over again. It seems sensible to cache already compiled patterns into a map for quick resolution.
Unfortunately, it does not improve the situation in #1409 too much. The majority of processing time is spent walking the directory tree, which is possibly bound by I/O.
This was referenced Jun 12, 2020 Compile each file match pattern only once #1411 Closed Build context scan feels slow when directory contains large file tree #1409 Closed bsideup added this to the next milestone Jun 12, 2020 bsideup reviewed Jun 16, 2020View reviewed changes
Comment thread docker-java-core/src/main/java/com/github/dockerjava/core/GoLangFileMatch.java
Outdated
|
|
||
| private static final String PATTERN_CHARS_TO_ESCAPE = "\\.[]{}()*+-?^$|"; | ||
|
|
||
| private static final Map<String, Pattern> PATTERNS = new HashMap<>(); |
bsideup commented Jun 17, 2020
Copy link Copy Markdown
Member
|
@swiedenfeld I was about to merge it but then realized... if the app is long running, such cache may eventually explode and cause an OOM. Since the class is in |
swiedenfeld commented Jun 17, 2020
Copy link Copy Markdown
Contributor
Author
|
@bsideup Good point. I was unaware it could be running long as I focused on its use in build step. There, the number of ignore patterns must be bounded by the lines in For the TTL, do you suggest a reasonable time interval until cache entries expire? |
bsideup commented Jun 17, 2020
Copy link Copy Markdown
Member
|
@swiedenfeld there are a few usages of docker-java that run for hours, days or even months :D Since it parses the user input, there is no guarantee that the set will be final, despite the relationship to "a few lines in For TTL, I'd suggest something like 1 hour. Alternatively, IIRC Guava can limit by the cache size, which may be another option (to limit it to 25Mb, or 10k patterns, or similar) |
bsideup commented Jun 24, 2020
Copy link Copy Markdown
Member
|
@swiedenfeld ping :) |
swiedenfeld commented Jun 24, 2020
Copy link Copy Markdown
Contributor
Author
|
pong :) |
Compile each file match pattern only once
cea9aff
#1409swiedenfeld changed the title Compile each file match pattern only once Cache file match patterns Jun 24, 2020 swiedenfeld changed the title Cache file match patterns Memoize file match patterns Jun 24, 2020
Update GoLangFileMatch.java
f54ffdd
bsideup
approved these changes
Jun 25, 2020
View reviewed changes
bsideup commented Jun 25, 2020
Copy link Copy Markdown
Member
|
@swiedenfeld FYI I just changed some defaults and will merge as soon as CI is green :) |
c3661f3
into
docker-java : master
Jun 25, 2020
swiedenfeld
deleted the
compile_less_patterns
branch
June 25, 2020 11:15
swiedenfeld
mentioned this pull request
Jul 27, 2020
Accelerate build context directory file walk
#1442
Closed
hidingmyname
mentioned this pull request
Oct 30, 2026
Empty directories inside a .dockerignore-excluded directory are still added to the build context
#2701
Open
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment