Skip to content

fix module source cache invalidation + cleanup api - #9505

Merged
sipsma merged 64 commits into
dagger:mainfrom
sipsma:simplify-module-load-take3
Feb 18, 2025
Merged

sipsma merged 64 commits into
dagger:mainfrom
sipsma:simplify-module-load-take3

Conversation

@sipsma

@sipsma sipsma commented Feb 4, 2025 •

Copy link
Copy Markdown
Contributor

🔥 Breaking Change

This improvement comes with a few breaking changes that are not expected to impact most users. Impacted users are those who:

  • have function code that imports local libraries outside of the dagger module source directory
  • rely on a package manager configuration file (e.g. go.mod) that exists in a parent directory of the dagger module source directory

They may need to update their dagger.json configuration file to add an explicit "include" setting to ensure those extra files or directories are loaded with the module. This is because numerous files previously implicitly loaded are now skipped by default, which contributes to the performance improvements.

For example, if your module code is in .dagger and relies on the go.mod file in the parent directory, you would add the following to your dagger.json file:

{
  "include": ["../go.mod", "../go.sum"]
}

The values in the "include" array are relative to the directory containing dagger.json. They can be also be glob patterns (e.g. "**/*.txt"). To explicitly exclude some files matched by a previous include pattern, you can prepend the include pattern with a ! character (e.g. "!**/foo.txt").

  • Previously, the exclude setting existed but has now been superseded by prefixing an include pattern with a ! character. However, this is backwards-compatible, so existing exclude settings will be automatically turned into equivalent !-prefixed include settings when running dagger develop. No user intervention is needed.

The core API's ModuleSource and Module types have also undergone some cleanup that includes breaking changes. Most users do not interact with these APIs, but any that do may need some minor adjustments to their code. In particular:

  • Module.initialize no longer needs to be called; the module is initialized on creation
  • ResolveFromCaller no longer needs to be called for local module sources; context is automatically loaded and resolved efficiently as needed by other API calls

Finally, an undocumented feature called views has been removed as it has been superseded by default path arguments.


Goals here are:

  • Fix various sources of excessive module building cache invalidation
    • changing completely unrelated source files in context
    • building different git commits that have no changes in the module source
    • etc.
  • Use the filesync improvements + new caching features to cleanup tons of cruft from the API (ResolveFromCaller, Module.initialize, etc.)
  • Setup for more performance improvements like better module remote caching, general function call caching, etc.
    • This step is a pre-req in that it gives us precise control over the cache keys of module source and modules themselves, which is needed first in order to have any more improvements to their cacheability

So far the results are looking good.

For some concrete numbers, here are load module times for the dagger-dev's module in Dagger's repository under different scenarios:

  • dagger call --help on new engines with an empty cache
    • v0.15.4: 1m20s
    • v0.16.0: 1m1s
    • ~23% faster
  • re-running dagger call --help with no file changes in the repo:
    • v0.15.4: 10.9s
    • v0.16.0: 2.8s
    • ~74% faster
  • re-running dagger call --help after making a change to a random source code file in the repo:
    • v0.15.4: 32.1s
    • v0.16.0: 2.8s
    • ~91% faster

The difference in 2. above of 10x speedup should make our day to day development quite a bit less painful; a lot less waiting around an extra 30s every time any change is made.

In terms of the simplifications, the net deletion of over 4k lines of code is indicative of success so far there 😄


TODOs:

  • get all integ tests passing, anticipating a lot of corner case squashing from stuff missed during refactoring
  • dedupe a bunch of copy-pasta chunks of code
  • cleanup various TODO comments (fix dagger install telemetry, etc.)
  • fill in missing api doc strings
  • appease linter
  • write up breaking change
  • remove more old cruft like RequiredPaths from sdks (now unused but still laying around)
  • update daggerverse code, coordinate release of it
    • PR out + tested in other repo

Comment thread cmd/dagger/module.go Resolved
Comment thread core/schema/modulesource.go Resolved
Comment thread core/modulesource.go Resolved
Comment thread core/schema/module.go Resolved
Comment thread core/schema/modulesource.go Resolved
@sipsma
sipsma force-pushed the simplify-module-load-take3 branch 8 times, most recently from b29e701 to 8d9afe3 Compare February 11, 2025 21:23
@sipsma sipsma added this to the v0.16.0 milestone Feb 12, 2025
@sipsma
sipsma force-pushed the simplify-module-load-take3 branch 12 times, most recently from fd81d0c to 0a3b94b Compare February 14, 2025 04:23
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the simplify-module-load-take3 branch from b12dd30 to ca58af8 Compare February 18, 2025 21:59
@sipsma
sipsma force-pushed the simplify-module-load-take3 branch from b42de4a to 560ec15 Compare February 18, 2025 23:14
@sipsma
sipsma merged commit abe35c5 into dagger:main Feb 18, 2025
@TomChv TomChv mentioned this pull request Feb 19, 2025
5 of 6 tasks
TomChv pushed a commit to TomChv/dagger that referenced this pull request Feb 20, 2025
The current implementation is broken because the way SDK is loaded since dagger#9505
is closely coupled with module source.
But in the client gen case, the generator
isn't the SDK itself, it could be but it could also
be an external one.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to TomChv/dagger that referenced this pull request Feb 20, 2025
The current implementation is broken because the way SDK is loaded since dagger#9505
is closely coupled with module source.
But in the client gen case, the generator
isn't the SDK itself, it could be but it could also
be an external one.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to TomChv/dagger that referenced this pull request Feb 20, 2025
The current implementation is broken because the way SDK is loaded since dagger#9505
is closely coupled with module source.
But in the client gen case, the generator
isn't the SDK itself, it could be but it could also
be an external one.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to TomChv/dagger that referenced this pull request Feb 21, 2025
The current implementation is broken because the way SDK is loaded since dagger#9505
is closely coupled with module source.
But in the client gen case, the generator
isn't the SDK itself, it could be but it could also
be an external one.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to TomChv/dagger that referenced this pull request Feb 24, 2025
The current implementation is broken because the way SDK is loaded since dagger#9505
is closely coupled with module source.
But in the client gen case, the generator
isn't the SDK itself, it could be but it could also
be an external one.

Signed-off-by: Tom Chauveau <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark triggers pre-merge benchmarks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module include/exclude unexpectedly impacts other local dependencies

4 participants