as / a

A graphical text editor
BSD 3-Clause "New" or "Revised" License
345 stars 25 forks source link

a: win: window upload is inefficient #94

Closed as closed 6 years ago

as commented 6 years ago

The current logic to update a window is to spawn N go routines and have each one call window.Upload() with the rectangle-bound sub-image. This is inefficient because:

1.) It spawns an unbounded amount of goroutines in a short amount of time, causing a burst of CPU usage when many rectangles are cached. Each goroutine has a short lifespan and the creation of the goroutine sometimes takes as long as the operation it performs

2.) Smaller rectangles are served last, which is computationally less desirable because it's a variant of a negated shortest-job-first scheduling algorithm, which is computationally less desirable.

The solution is to take the example from as/frame/examples/fast/fast.go and put it in every win from as/ui/win/win.go. This will make each window spawn N long-lived goroutines that do all the work, where N is the value of runtime.NumCpus.