Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimise future fields: use regular reference when possible #418

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions sdk/workflow-tengo/src/smart.lib.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,17 @@ resource = func(r) {
* @return field: smart.field
*/
getFutureField: func(name, fieldType, ...eph) {
if self.hasField(name) {
// We already have a field with given name.
// We can refer it directly to not produce complicated resource trees on backend side.
return self.getField(name)
}

isEph := strictSelf.isEphemeral()
if len(eph) > 0 {
isEph = eph[0]
}

return _getFutureField(strictSelf, name, fieldType, isEph)
},

Expand All @@ -470,14 +477,15 @@ resource = func(r) {
}

if is_array(nameOrPath) {
// Traverse fields
current := strictSelf
for name in nameOrPath {
current = current.getFutureField(name, "input", isEph)
}
return current
} else {
return self.getFutureField(nameOrPath, "input", isEph)
}

return self.getFutureField(nameOrPath, "input", isEph)
},

/**
Expand Down Expand Up @@ -842,6 +850,13 @@ field = func(f) {
* @return field: smart.field
*/
getFutureField: func(name, fieldType, ...eph) {
fldInfo := self.info()
if fldInfo.Value != 0 && fldInfo.Error == 0 && fldInfo.Type != constants.FTYPE_OUTPUT {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure we need this. This optimisation may 'remove' one element from TIDs chain which will affect deduplication and recovery. But when we skip outputs, it seems like we almost disable the optimisation completely.

Copy link
Member

Choose a reason for hiding this comment

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

The most risky thing here is to optionally add a non-ephemeral future-field, based on some state that may change depending on how certain races in the system are resolved. This way we will introduce a different CID (not TID) in the chain, which in tern may spoil de-duplication.

// We can't do this optimisation for outputs, as we affect deduplication and
// recovery logic in that case, artificially throwing one element from the topology.
return resource(fldInfo.Value).getFutureField(name, fieldType, eph...)
}

isEph := strictSelf.isEphemeral()
if len(eph) > 0 {
isEph = eph[0]
Expand Down
Loading