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:
@@ -45,9 +45,20 @@ import (
|
||||
// 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.)
|
||||
@@ -102,12 +113,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
|
||||
|
||||
Reference in New Issue
Block a user