~/bend-docscommunity

performance/missed_fork.bend checks

raw source on the hub · import bend-lint-rules@0.3.0.0/performance/missed_fork.bend as Missed_fork

performance/missed_fork: calls of a definition to itself that could run in parallel, but run one after the other: two or more in one expression (f(x) + f(y), Node{f(x), f(y)}), or in lets that follow each other (l = f(x), then r = f(y)), where no call uses the result of another. Heuristics: Bend forks only the values of a parallel let (a b = f(x) f(y)), and its calls are independent, as Bend is pure. Whether a fork pays depends on how much work each call does, which the rule cannot see: measured on the CPU, forking a walk of a 1M-leaf tree, called 10 times, made it 2.5x faster; forking the same walk of 1k-leaf trees, called 100,000 times in a loop, made it 3.9x slower; forking a small expression tree that BendSR evaluates once per data point made it 230x slower. The JS lane runs on one thread, so it does not gain. Calls in different values of Bool.pick, or on the two sides of && or ||, are alternatives, not both needed (see performance/eager_branch): they do not count together. Calls written the same way compute the same value, so they are left to performance/repeated_call, which asks to compute it once (pow2(30): 0.1 s, against 0.6 s forked). It skips a definition that returns IO: its calls build effects, they do not run them. A call inside another call of itself, inside a lambda, or in a type, does not count.

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

Types

type Owner source · line 25 · raw

Data

What judging one definition reads: its name as the check names it and as written, whether it returns IO (its calls build effects, they do not run them), and the file's text.

type Bound source · line 30 · raw

Data

A let that binds one name to a call of its definition to itself: where its binder starts, the binder as written, the binder, and the call.

type Run source · line 34 · raw

Data

The lets of a run so far (last first), their binders, and the findings so far (last first).

Definitions

def trim.go source · line 39 · raw

@cs:List<&2, Char> -> List<&2, Char>

Functions =========

def trimmed source · line 46 · raw

@s:String -> String

def is_choice source · line 51 · raw

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

Whether an application's nodes call Bool.pick, Bool.and or Bool.or: its arguments are alternatives, each an expression of its own.

def is_boundary source · line 59 · raw

@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> Bool

Whether a node of this syntax ends the expression a call is in.

def returns_io source · line 71 · raw

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

Whether a definition's nodes say it returns IO, as written.

def calls.to source · line 104 · raw

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

Whether an application's nodes call target: its function is a reference to it.

def called.at source · line 112 · raw

@call:Bool -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span>

out with the span of a call of target (if call), where the call is.

def calls source · line 126 · raw

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

Where the calls of target among nodes and under them are (onto out, last first), in the expression they start: a node that ends it starts another, and so does each argument of a choice (Bool.pick, Bool.and, Bool.or); a call inside another call of target does not count: none does if nodes are the parts of one, or of a choice (inside).

def texts source · line 152 · raw

@spans:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @+text:String -> @out:List<&2, String> -> List<&2, String>

def names source · line 159 · raw

List<&2, String>

def binders source · line 163 · raw

@texts:List<&2, String> -> @ns:List<&2, String> -> @out:List<&2, String> -> List<&2, String>

Fresh names for n values, as a parallel let binds them.

def quoted source · line 176 · raw

@texts:List<&2, String> -> @out:List<&2, String> -> List<&2, String>

def costs source · line 183 · raw

String

def expected source · line 186 · raw

String

def count source · line 189 · raw

@texts:List<&2, String> -> String

def Call.message source · line 192 · raw

@loop:String -> @+texts:List<&2, String> -> String

def alike.go source · line 208 · raw

@texts:List<&2, String> -> @+first:String -> @ok:Bool -> Bool

The finding about an expression at span that holds the calls at spans (last first), if they are two or more.

def is_alike source · line 218 · raw

@texts:List<&2, String> -> Bool

Whether texts, the calls of one finding, are all written the same way.

def Call.finding.of source · line 225 · raw

@many:Bool -> @+spans:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @+owner:Owner -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def Call.finding source · line 242 · raw

@+spans:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @owner:Owner -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def starts source · line 250 · raw

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

Whether the node below path starts an expression: the node above it ends one, or is a choice.

def called source · line 260 · raw

@value:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @target:String -> Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node>

The call of a let's value, if the value is a call of target, typed or not.

def bound source · line 284 · raw

@+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @+owner:Owner -> Maybe<&2, Bound>

A let that binds one name to a call of target, if node is one.

def uses source · line 307 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+binders:List<&2, U32> -> @found:Bool -> Bool

Whether a variable the file writes, of one of binders, is among nodes or under them, or found.

def Bound.texts source · line 318 · raw

@bounds:List<&2, Bound> -> @+text:String -> @written:List<&2, String> -> @called:List<&2, String> -> Pair(List<&2, String>, List<&2, String>)

def Run.lets source · line 331 · raw

@written:List<&2, String> -> @called:List<&2, String> -> @out:List<&2, String> -> List<&2, String>

def Run.message source · line 342 · raw

@loop:String -> @texts:Pair(List<&2, String>, List<&2, String>) -> String

def Run.alike source · line 360 · raw

@texts:Pair(List<&2, String>, List<&2, String>) -> Bool

Whether the calls of a run of lets are all written the same way.

def Bound.from source · line 365 · raw

@bound:Maybe<&2, Bound> -> U32

def Run.finding source · line 373 · raw

@+bounds:List<&2, Bound> -> @+owner:Owner -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The finding about a run of lets (last first), if it has two lets or more: from the first's binder to the last's call.

def Run.add source · line 390 · raw

@bound:Maybe<&2, Bound> -> @owner:Owner -> @run:Run -> Run

The run after a let (bound, if it is one): the let joins it if its call uses no binder of the run; else the run ends, and the let starts the next.

def Run.finding.end source · line 406 · raw

@run:Run -> @owner:Owner -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def chain source · line 417 · raw

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

The findings about the runs of lets that follow each other from node, a let, after run: each next let is the rest of block of the one before, while its call uses no binder of the run.

def follows source · line 434 · raw

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

Whether a let below path goes on a run from the let above it: it is that let's rest of block, and that let binds one name to a call.

def roots source · line 446 · raw

@root:Bool -> @node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @+owner:Owner -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The finding about the calls of the expression a node starts, if it starts one (root).

def lets source · line 459 · raw

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

The findings about the runs of lets from a node, if it starts one (head).

def visit source · line 468 · raw

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

The findings at a node of a definition below path: about the calls of the expression it starts, and about the runs of lets from it, if it starts one.

def defs source · line 493 · raw

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

def run source · line 521 · raw

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

def rule source · line 524 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule