Skip to content

core: speed up loading of builtin SDKs - #6714

Merged
sipsma merged 3 commits into
dagger:mainfrom
sipsma:improve-go-sdk-loading
Feb 23, 2024
Merged

sipsma merged 3 commits into
dagger:mainfrom
sipsma:improve-go-sdk-loading

Conversation

@sipsma

@sipsma sipsma commented Feb 22, 2024 •

Copy link
Copy Markdown
Contributor

@vito noticed a while back that we were spending a lot of time loading the builtin Go SDK tarball. This fixes that bottleneck by avoiding use of local imports for built-in SDKs and instead using OCI store sources, which avoid the various problems with local sources (re-importing when used in parallel, need to always re-read tarball when importing containers, etc.).

@sipsma
sipsma force-pushed the improve-go-sdk-loading branch from 7837ad8 to 3799303 Compare February 22, 2024 18:30
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Feb 22, 2024

Copy link
Copy Markdown
Contributor Author

Confirmed that the memory usage issues were pre-existing: #6719

Also, while test execution time is noisy, it seems like there's a pretty consistent improvement in CI runtime. Engine & CLI / test has been taking ~10m consistently so far, whereas on main recent runs ranged from 15m-21m. Same approx improvement for testdev.

I suspect the improvements for day-to-day usage of dagger locally will be less dramatic in terms of individual runs, but they should add up over the course of the day. And any users running shared engines with lots of clients connecting to them (i.e. for CI) should see the benefits more clearly.

I may end up doing another iteration on this in response to #6706 (comment), but it should most likely be incremental rather than throwing everything in this PR away, so worth merging this one as is to get the test runtime improvements in the meantime.

@sipsma
sipsma marked this pull request as ready for review February 22, 2024 19:18
@sipsma
sipsma requested review from a team as code owners February 22, 2024 19:18
@sipsma sipsma modified the milestones: v0.10.0, v0.10.x Feb 23, 2024

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳🦜

My laptop thanks you. 🙏

Comment thread core/schema/host.go

dagql.Func("builtinContainer", func(ctx context.Context, parent *core.Query, args struct {
Digest string `doc:"Digest of the image manifest"`
}) (*core.Container, error) {

@vito vito Feb 23, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #6704 (comment) - are you thinking of asserting dagql.IsInternal here to avoid people depending on it? Or using dagql.IsInternal to conditionally register the API somehow? (That'd be neat)

There's an interesting consideration either way: you'd want to prevent these hidden/internal APIs from ending up in an ID that the user cares about, since that ID would then only work if it was part of an internal call.

I think everything that matters might still work since we don't want this to end up in any published/long-term IDs anyway (it's an impl. detail of the APIs that actually do end up in IDs). But it's a little spooky. Just fyi!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or using dagql.IsInternal to conditionally register the API somehow? (That'd be neat)

Ya that's what I was imagining. And maybe also grouping everything in this category under like Query.internal or something just to avoid hidden namespace conflicts between user APIs and APIs they don't even know about.

There's an interesting consideration either way: you'd want to prevent these hidden/internal APIs from ending up in an ID that the user cares about, since that ID would then only work if it was part of an internal call.

Right right, I guess you could deal with that by returning always returning a dagql.Instance from these internal APIs such that the returned instance is constructed purely from non-internal APIs. So like builtinContainer could use Select to create a Container from scratch using withRootfs, withEnvVariable, etc. etc. and return that instance.

I don't know if we could enforce this automatically or if it'd just need to be a manually enforced rule. But yeah definitely a medium sized wrench in that whole idea...

@jedevc jedevc Feb 23, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 I also really want this for #6601 actually!

The accessor field/and co on the secret object shouldn't be visible anywhere to SDK callers, it shouldn't appear in the graphql documentation either. They're only ever needed so that setSecret can return a dagql.Instance anyways.

f, err := c.Host().File(tarballPath).Sync(ctx)
if err != nil {
panic(err)
func goSDKContent(ctx context.Context, c *dagger.Client, arch string) dagger.WithContainerFunc {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like these could be deduped (I am the linter now)

nbd either way though, not worth it if it explodes complexity or requires 1000 args or tiny functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ya totally, split out the sections that were identical between the 3 to a separate func

Comment thread internal/mage/util/engine.go Outdated
return ctr.
WithEnvVariable(distconsts.GoSDKManifestDigestEnvName, manifestDgst).
WithDirectory(distconsts.EngineContainerBuiltinContentDir, sdkDir, dagger.ContainerWithDirectoryOpts{
Include: []string{"blobs/"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat - I've never actually realized that WithDirectory copies additively to the target directory. 🤯

@sipsma
sipsma merged commit be31227 into dagger:main Feb 23, 2024
@jedevc

jedevc commented Feb 23, 2024

Copy link
Copy Markdown
Contributor

Nice, neat solution! 🎉 (sorry I didn't review earlier, but have a post-merge LGTM from me)

@jedevc jedevc mentioned this pull request Feb 23, 2024
4 tasks done
vito pushed a commit to vito/dagger that referenced this pull request Feb 27, 2024
* core: speed up loading of builtin SDKs

Signed-off-by: Erik Sipsma <[email protected]>

* regen docs/sdks

Signed-off-by: Erik Sipsma <[email protected]>

* dedupe sdk->content dir impl code

Signed-off-by: Erik Sipsma <[email protected]>

---------

Signed-off-by: Erik Sipsma <[email protected]>
@jedevc jedevc mentioned this pull request Mar 6, 2024
11 of 13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants