Skip to content

High cpu usage by Display module #179

@Jon-Biz

Description

@Jon-Biz

I'm having a lot of fun with this, but ran into this performance issue.

I'm using the Display module to render a rectangular display, and getting 100% cpu usage from this line:

    /**
     * Timer tick: update dirty parts
     */
    _tick() {
        this._backend.schedule(this._tick);
        if (!this._dirty) {
            return;
        }

backend.schedule() is this line:

schedule(cb) { requestAnimationFrame(cb); }

It appears that, as long as there's nothing to do, it just executes and returns as fast requestAnimationaly possible. Adding a 2ms setTimeout to this._backend.schedule(this._tick) dropped chrome's cpu usage from 100% to 7%.

Implementing an optional rate limiter would trivial, but I wanted to make sure that I'm not using it wrong before submitting a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions