~/bend-docscommunity

performance/missed_fork.bend fails

raw source on the hub · import bend-lint-rules@0.1.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.1.0.0/linter/lint.bend as Lint
import bend-lint-api@0.1.0.0/shared/lists.bend as Lists
import bend-lint-api@0.1.0.0/shared/strings.bend as Strings