GithubHelp home page GithubHelp logo

Priorities about mini-runner HOT 3 OPEN

drkibitz avatar drkibitz commented on May 22, 2024
Priorities

from mini-runner.

Comments (3)

drkibitz avatar drkibitz commented on May 22, 2024

To converge on the priority stuff, I'm seeing rather quickly that we would need to wrap your items in a listener object. Nothing to do with scoping the functions, it is just to have a higher level object to hold the reference, with description properties next to it, e.g. priority.

Here's what I'm thinking (note the changes to the loop in generateRun):

p.add = function(item, priority) {
    if (!item[this._name]) return;

    this.remove(item);

    const listenersCopy = this.listeners.slice();
    const l = listenersCopy.length;
    const listener = { item, priority };

    if (l > 0) {
        let i = l;

        while (i--) {
            // from end - if next has lower priority, insert now after
            if (listenersCopy[i].priority < listener.priority) {
                listenersCopy.splice(i + 1, 0, listener);
                break;
            }
            // from start - if next has equal priority, insert now before
            else if (listenersCopy[l - (i + 1)].priority === listener.priority) {
                listenersCopy.splice(l - (i + 1), 0, listener);
                break;
            }
        }
        this.listeners = listenersCopy;
    }  else {
        listenersCopy.push(listener);
    }
    this.listeners = listenersCopy;
};

MiniRunner.generateRun = function(name, argsLength) {
    const key = name + '|' + argsLength;
    let func = MiniRunner.hash[key];

    if (!func) {
        if (argsLength > 0) {
            let args = 'arg0';

            for(let i = 1; i < argsLength; i++) {
                args += ',arg'+i;
            }
            func = new Function(args, 'var listeners = this.listeners, i = listeners.length; while(i--) listeners[i].item.'+name+'('+args+');');
        } else {
            func = new Function(args, 'var listeners = this.listeners, i = listeners.length; while(i--) listeners[i].item.'+name+'();');
        }

        MiniRunner.hash[key] = func;
    }

    return func;
};

from mini-runner.

drkibitz avatar drkibitz commented on May 22, 2024

@GoodBoyDigital so I made some changes locally, and I'm seeing something odd, too good to be true even. Take a look at this:

benchmarking signals...
signals time 1.129935
listener updates 2000
benchmarking mini-signals...
mini-signals time 0.1500250000000001
listener updates 4000
benchmarking events...
events time 0.08157999999999993
listener updates 6000
benchmarking runner...
runner time 0.00013999999999987268
listener updates 8000
runner is 8070.964285721625x faster than signals
runner is 1071.607142858118x faster than mini-signals
runner is 582.7142857148152x faster than events

This is consistent... compared to the 25x, 2x, 1x average without my changes.

I can't believe my changes would have increased performance 500%, my expectation was that it might have dropped it by like 0.1% or something. I added the listener updates # log to make sure things were being called. I'm kind of at a loss here. See anything out of the ordinary, or curious? Make a PR? ;)

from mini-runner.

drkibitz avatar drkibitz commented on May 22, 2024

Nevermind I found the issue, definitely too good to be true.

from mini-runner.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.