FolkComputer / folk

🎁 Physical computing system.
https://folk.computer
Apache License 2.0
77 stars 4 forks source link

Reduce spurious recollects #84

Closed osnr closed 12 months ago

osnr commented 12 months ago

40fps -> 60+fps when terminal is out, probably greater performance increases the more load you're putting on the system.

Mostly fixes these:

image

At a high level, the idea is that if you have a collection (this is made-up syntax but):

When the collected matches for [list /someone/ detects tags /tags/] {
  foreach tag $tags { Claim $tag is a tag }
}

you don't want to retract the children Claim 3 is a tag immediately when the set of detects tags statements changes and unmatches the collect (e.g., when one of the detectors gives a new report), because that will destroy all downstream statements/force recomputation. You want to flag the collect for recollection later, then only retract children when that recollection is done. (the recollection will likely again produce Claim 3 is a tag, so you can reuse that entire subgraph and never throw it away)

Uses a priority queue for the operation queue (which we might not really need at this point, but it seems useful if we want to get smarter later)


Also adds operation log of first 10k operations, which you can view with this program (log.folk):

Wish the web server handles route "/log$" with handler {
  set log [Evaluator::getOperationLog]
  set body [list "<ol>"]
  foreach entry $log {
    if {$entry eq "Evaluate"} {
      lappend body {<li style="background-color: yellow;">Evaluate</li>}
    } else {
      lappend body "<li>[htmlEscape $entry]</li>"
    }
  }
  lappend body "</ol>"
  html [join $body ""]
}

You probably want to put some pages on the table, start the system, then look late in the log to see a representative frame's worth of operations. The log seems to impose very little overhead, so I'm leaving it in. It might be nice to build the web page in and make it rolling.

You'll see extra recollects in the log, but they mostly get suppressed by the collectNeedsRecollect flag.


Please test this on your system; I'll merge it by tomorrow if I don't hear of any problems.