~/bend-docscommunity

performance/template_value_field.bend checks

raw source on the hub · import bend-lint-rules@0.3.6.0/performance/template_value_field.bend as Template_value_field

performance/template_value_field: a value field of a record of functions that reads a template whose type is a record of functions. Bend writes a template where it is used, so a record of functions passed as one is built again at each use; a field that is not a function is computed then, and reading the template builds its whole record, closures too, to read a part of it, then frees the rest. Heuristics: measured on a combinator of two records of functions, nested 6 deep and run 2M times: 1.7 s with a count as a value field, against 1.0 s with the count under a lambda (u => ..), on the C lane (one thread), and 49 s against 14 s on the JS lane, with the same output; issue #2 measured 6% more time on a nested model, and nothing on a shallow one, as the cost doubles with each level. The lambda moves the work to each read: with the count read on every step too, it took 2.4 s against 1.9 s. A record of functions is a datatype of the program with a field whose written type is a function; a record that the rule judges is built in live code, outside a lambda, with a lambda among its fields: a record of values only is a result, built once. A template of another type (a number, a function, a list) builds no record of closures, and is not judged. A use in a type, or under a lambda, does not run when the record is built.

4 imports
import Base
import bend-lint-api@0.3.6.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.6.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.6.0/shared.bend as Shared

Types

type Owner source · line 24 · raw

Data

What judging the uses of one definition's templates reads: the binders of its templates whose type is a record of functions, and its name as written.

Definitions

def message source · line 29 · raw

@+template:String -> @owner:String -> String

Functions =========

def records.step source · line 37 · raw

@+u:Unit -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @found:Bool -> Bool

def records source · line 52 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @out:List<&2, String> -> List<&2, String>

The datatypes among nodes with a field whose written type is a function, by the name the check gives them, onto out.

def program.records source · line 72 · raw

@sources:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Source> -> @out:List<&2, String> -> List<&2, String>

def written source · line 80 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> String

The datatype a type's nodes write, by the name the check gives it, or "" for another form (a function, a sort).

def templates source · line 90 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+records:List<&2, String> -> @out:List<&2, U32> -> List<&2, U32>

The binders of the templates among a definition's nodes whose type is one of records, onto out.

def is_lambda source · line 111 · raw

@node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> Bool

def is_built source · line 120 · raw

@path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @found:Bool -> Bool

Whether a node below path is computed when a record of functions is built: under no lambda, and in a construction with a lambda among its fields (found, once one is).

def visit source · line 131 · raw

@+owner:Owner -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def defs source · line 147 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+records:List<&2, String> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The findings in the definitions among nodes that have templates of records, onto out (last first).

def run source · line 175 · raw

@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)

def rule source · line 184 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule