Coder Social home page Coder Social logo

Comments (15)

spaceone avatar spaceone commented on May 26, 2024 1

Maybe we could implement a method self.fastcall() ?

from circuits.

prologic avatar prologic commented on May 26, 2024

👍 Worth looking in to :)

I suspect it might have something to do with the fact that coroutines are handled in the "next tick" so to speak; whereas fired events are "queued up" for immediately handling.

But maybe we can improve this?

from circuits.

prologic avatar prologic commented on May 26, 2024

With a much simpler implementation of this "slow test":

from circuits import Component, Event


class counter(Event):
    """counter Event"""

    complete = True


class Slow(Component):

    def started(self, *args):
        #  self.fire(counter(10))
        yield self.call(counter(10))

    def counter(self, n):
        for i in xrange(n):
            print i
            yield i

    def counter_complete(self, *args):
        raise SystemExit(0)

Slow().run()

I only see a ~10% performance drop in using self.call() which IHMO is acceptable seeing what it's doing and all :) Thoughts?

from circuits.

spaceone avatar spaceone commented on May 26, 2024

That code does not what my code does. You are call()-ing 1 time not 10/30 times (which is a valid use case). Where then 10% is very much. At least it must be documented, also using call() is useless then if it is in the endeffect slower than just fire()ing.

from circuits.

prologic avatar prologic commented on May 26, 2024

Hmm I'll have to study your contrived example a bit more :) I'm not quite following it yet :)

from circuits.

spaceone avatar spaceone commented on May 26, 2024

Real life code is always better: spaceone/circuits.http@ef5d7f6

from circuits.

prologic avatar prologic commented on May 26, 2024

Yeah okay I see :) I'll have to play with this some more and see what's going on. To be honest I'm not sure why you're using coroutines (or were trying to) there anyway?

from circuits.

spaceone avatar spaceone commented on May 26, 2024

Well, I thought call is not just equivalent to yield self.wait(self.fire(event).event). I thought it would just call the event handlers synchroniously. Now I looked at the code and I am smarter ;)

from circuits.

prologic avatar prologic commented on May 26, 2024

Ahh so in your particular case you were calling the wrong API method? yield self.wait() is indeed NOT equivalent to self.call() :) Both in effect create coroutines!

from circuits.

spaceone avatar spaceone commented on May 26, 2024

What are the exact differences between call() and wait()? In my particular case I want to call the handlers as soon as possible. I probably misunderstood how call() is meant to be used?

from circuits.

prologic avatar prologic commented on May 26, 2024

Yeah so call/wait are essentially the same. .call() does a .fire() and .wait(), whilst .wait() only wiats for an event's completion. Both are used to write synchronous code that is otherwise asynchronous underneath, both turn the event handler into a coroutine (_because you _have* to yield*).

from circuits.

prologic avatar prologic commented on May 26, 2024

Any further thoughts/comments on this? Do we need to change/fix/update anything here? Improve the documentation around this perhaps?

from circuits.

prologic avatar prologic commented on May 26, 2024

@spaceone Do you have any thoughts on improving this at all -- Or should we just document it better? call/wait provide coroutines (cooperative threading); I would never expect them to be as performant as "fire and forget". I have however observed the same behaviour as what you've described in that using coroutiens does cost a bit of performance for the sake of "synchronization".

from circuits.

prologic avatar prologic commented on May 26, 2024

Maybe we could implement a method self.fastcall() ?

I'm not sure; but it would be backwards compatible at least. New API.

from circuits.

spaceone avatar spaceone commented on May 26, 2024

Maybe fixing #136 via #213 already solves this problem - at least it gets improoved

from circuits.

Related Issues (20)

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.