lang: Improve graph shape with speculative execution

Most of the time, we don't need to have a dynamic call sub graph, since
the actual function call could be represented statically as it
originally was before lambda functions were implemented. Simplifying the
graph shape has important performance benefits in terms of both keep the
graph smaller (memory, etc) and in avoiding the need to run transactions
at runtime (speed) to reshape the graph.

Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
This commit is contained in:
James Shubin
2025-03-17 02:31:01 -04:00
parent 9c9f2f558a
commit 37bb67dffd
139 changed files with 1871 additions and 262 deletions

View File

@@ -54,9 +54,20 @@ const (
// RegisteredFuncs maps a function name to the corresponding function scaffold.
var RegisteredFuncs = make(map[string]*Scaffold) // must initialize
// Info holds some information about this function.
type Info struct {
Pure bool // is the function pure? (can it be memoized?)
Memo bool // should the function be memoized? (false if too much output)
Fast bool // is the function slow? (avoid speculative execution)
Spec bool // can we speculatively execute it? (true for most)
}
// Scaffold holds the necessary data to build a (possibly polymorphic) function
// with this API.
type Scaffold struct {
// I is some general info about the function.
I *Info
// T is the type of the function. It can include unification variables.
// At a minimum, this must be a `func(?1) ?2` as a naked `?1` is not
// allowed. (TODO: Because of ArgGen.)
@@ -124,12 +135,23 @@ func Register(name string, scaffold *Scaffold) {
panic(fmt.Sprintf("could not locate function filename for %s", name))
}
funcInfo := &wrapped.Info{}
if scaffold.I != nil {
funcInfo = &wrapped.Info{
Pure: scaffold.I.Pure,
Memo: scaffold.I.Memo,
Fast: scaffold.I.Fast,
Spec: scaffold.I.Spec,
}
}
// register a copy in the main function database
funcs.Register(name, func() interfaces.Func {
return &Func{
Metadata: metadata,
WrappedFunc: &wrapped.Func{
Name: name,
Name: name,
FuncInfo: funcInfo,
// NOTE: It might be more correct to Copy here,
// but we do the copy inside of ExprFunc.Copy()
// instead, so that the same type can be unified