Skip to content

dagql ID format + digest improvements to support ID walking - #6836

Merged
sipsma merged 11 commits into
dagger:mainfrom
sipsma:id-walk
Mar 8, 2024
Merged

sipsma merged 11 commits into
dagger:mainfrom
sipsma:id-walk

Conversation

@sipsma

@sipsma sipsma commented Mar 6, 2024 •

Copy link
Copy Markdown
Contributor

This is another spin-off of #6747 (sibling to #6806) with the goal of enabling us to efficiently "walk" IDs in order to find all instances of a given type embedded in their DAG.

This is accomplished by updating the dagql ID format to store a map of digest->fields for ID with that digest, with any other references to IDs being via that digest (whereas previously we recursively repeated every ID every time it occurred), in addition to various associated improvements to only re-calculate those digests when needed.

The goal here is to support the aforementioned need for ID walking, but the hope is that this will be beneficial in terms of performance (both memory and cpu) to the engine/CLI/cloud too.

Draft pending:

  • Fix ephemeral errors I'm seeing only when running manually where certain types appear to be unexpectedly nil (until a re-run). Doesn't happen in tests (yet)...
    • have not repro'd this for a while. I made a lot of fixes and simplifications to ensure IDs are totally immutable, so if this is was some race condition involving that then there's a halfway decent chance it no longer exists. Will keep running manually either way.
  • Doc what's going on in comments more, address inline //TODO comments
  • Uncomment and test the referencedTypes func (which is what implements the logic for "give me all the instances of types implementing a given interface in the DAG of a provided ID")
    • decided to just rm this for now; not worth it when it would only be called in tests. It will come along the ride with the next PR that actually uses it to isolate session resources.

@sipsma
sipsma marked this pull request as draft March 6, 2024 10:07
@sipsma
sipsma force-pushed the id-walk branch 2 times, most recently from ce89536 to 699b661 Compare March 7, 2024 02:06
@sipsma sipsma changed the title [WIP] dagql ID format + digest improvements to support ID walking dagql ID format + digest improvements to support ID walking Mar 7, 2024
@sipsma
sipsma marked this pull request as ready for review March 7, 2024 02:21
@sipsma
sipsma requested a review from vito March 7, 2024 02:21

@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.

Super happy to see this, will review/write more but spent way too long on one comment already 😅

Comment thread dagql/idproto/id.proto Outdated
Comment on lines 14 to 15

@vito vito Mar 7, 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.

Would prefer the protocol type to not be prefixed with Raw, but I can see how it helps with the rest of the code.

A bit of a context dump:

The protocol details will matter soon since the current plan is to have the frontend parse ID protobuf payloads sent over in Otel span attributes. We tried to avoid a frontend Protobuf dependency, but it's very awkward to translate arguments in particular into span attributes. We're already incentivized to have a stable ID format (#3923), and JS/TS should be good at protobuf anyway, so 🤷‍♂️ maybe it's fine?

Streaming the protobufs over will be 1000x better with this PR though: now we can just send infividual Fields over the wire, one per span, and have them all go into one big RawID client side, which is really 🔥😎👨‍🍳🤌💋

In the interest of getting this protocol stable more quickly, I'm siezing an opportunity here for some bikeshedding 😁

While we're changing names, hopefully we can find a better one than "ID." @aluzzardi and I found it too confusing while mocking up the Cloud API, and we landed on "Call" which I still like, since each of these things (currently Fields) corresponds to a function call in our new terminology.

So, building on Call, I dunno, "Chain?" (a...chain of function calls)

Suggested change
message RawID {
message Fields {
message Chain {
message Call {

"Thunk?" (an unevaluated 0-arity function; IDs are like serializable thunks)

Suggested change
message RawID {
message Fields {
message Thunk {
message Call {

Punt on it and just make "Call" the hero with a boring name for its wrapper?

Suggested change
message RawID {
message Fields {
message Envelope {
message Call {

"Scope"?

Suggested change
message RawID {
message Fields {
message Scope {
message Call {

I yield the floor 🙏

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.

Yeah Call SGTM.

For the "outer" type, I actually think DAG (or Dag, etc.) would be technically accurate (besides being on brand and all that 😁). It's more than a Chain because it stores the IDs not only for the chain of bases, it also has the IDs for any args of type ID, the ID of modules, etc. Each of the current *IDDigest fields in the types are the edges and the current RawID_Field type is the vertex type.

So something like:

message DAG {
  message Call {
    // The digest of the call that the field selection will be evaluated against.
    string baseCallDigest = 1;

    // ...

    // A unique digest of this Call
    string digest = 9;
  }

  // The digest of the Call for the "root" of the DAG. All other Calls
  // in this message are referenced by this one via their base, args or module.
  string rootCallDigest = 9;

  // Map of Call digests to the Call they represent. This structure
  // allows us to deduplicate occurrences of the same Call in the DAG.
  map<string, Call> callsByDigest = 10;
}

message CallModule {
  // The digest of the Call that provides the module.
  string callDigest = 1;

  // ...
}

message CallArgument {
  string name = 1;
  CallLiteral value = 2;
}

// A value passed to an argument or contained in a list.
message CallLiteral {
  oneof value {
    string callDigest = 1;
    // ...
  }
}

WDYT?

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'm good with that in principle - I almost recommended Graph/DAG but was afraid we'd be tempted to go back to Vertex 😂 - since mixing Graph and Functional terminology felt a little awkward. But maybe it's fine. I definitely see the upside of aligning with DAGger/DAGql. Though I think protobuf has strong opinions that might force it to be Dag instead of DAG.

Aside from that, think I'd prefer to just keep a flat set of types without prefixing or nesting them, just to leave the door open for other shapes/configurations/reuse. I think nesting Call under DAG will force its generated name to be Dag_Call, implying it's only ever used in the context of a DAG, which is true to some extent, but I mentioned earlier that we might be able to send individual Calls over OTel instead of a full DAG (though even in that case they would end up in a DAG eventually).

Same goes for the other types - they should probably just be Argument, Literal, Module. The CallArgument type is actually also used to represent object fields, so maybe it could even have a more generic name like NamedLiteral, but eh, Argument is clearer for the 99% case. If those prefixes are to avoid name clashes with the types used in by code, maybe we should just move the protobuf generated types into something like callpbv1?

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.

Aside from that, think I'd prefer to just keep a flat set of types without prefixing or nesting them, just to leave the door open for other shapes/configurations/reuse.

Yeah makes sense 👍

If those prefixes are to avoid name clashes with the types used in by code, maybe we should just move the protobuf generated types into something like callpbv1?

Also SGTM, especially in the context of this being used in a wider context by the frontend, etc.

Will make these updates.

@sipsma sipsma Mar 7, 2024 •

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.

@vito pushed that here: 87af4a1

  • dagql/call/callpbv1 has the proto codegen
  • dagql/call has all the wrappers around those types

I ended up leaving the wrapper type around callpbv1.DAG+callpbv1.Call named ID. Partially because the way its used abstracts over those two types, so neither DAG or Call really fit. And partially because renaming that low-level ID type to e.g. Call ended making a lot of the consuming code super awkward in terms of names.

So I guess the idea is that these wrapper types are specific to the dagql/engine use case and thus ID ends up being a clearer name. All of that is in a separate package from the pb though, so other future consumers won't be impacted.

@sipsma

sipsma commented Mar 7, 2024

Copy link
Copy Markdown
Contributor Author

@vito I did a double check around CLI performance since it no longer has that global cache of ID digests (not needed anymore). The RSS+cpu usage looks to be about the same when compared with main. Which is good in that it's not worse, but would have been cool if we got an improvement as a side-effect of all this.

I suspect that improvements might become noticeable with particularly complicated function calls, specifically those that previously resulted in IDs growing huge due to repeated serialization of the same ID across the DAG.

But the main reason the performance is about the same seems to be that the performance bottlenecks in the CLI lie elsewhere, specifically in idtui.CollectSteps and idtui.Step.StartTime. Attached a pprof viz of a CPU profile I grabbed while testing this.
profile

Addressing that is way out of scope, so leaving as is.

@vito

vito commented Mar 7, 2024

Copy link
Copy Markdown
Contributor

@sipsma That makes sense. It's too bad we don't have an offhand example for huge IDs, but it seems like an obvious theoretical issue. Also not surprised there are bottlenecks elsewhere in the TUI as it has had very little optimization done to it yet. Thanks for checking!

@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.

So happy to see all those error return values go away, and the janky digest cache. 🥲

Comment thread dagql/call/id.go Outdated

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.

NB: on my otel branch I changed this to include the receiver, but nothing uses this at the moment, and arguably the receiver is already accessible, so maybe it's helpful to have a distinction in case we want to treat argument + receiver differently in the UI. So I'm good with leaving this as-is.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma merged commit 6ac3c71 into dagger:main Mar 8, 2024
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.

2 participants