Giter VIP home page Giter VIP logo

Comments (7)

eregon avatar eregon commented on July 29, 2024 1

@chrisseaton I don't believe coroutines (not continuations) "fundamentally don't match the execution model we are using at the moment". See my previous answer.
Using that patch would allow to have similar performance characteristics as MRI.
But yes, it's not practical to require a custom JVM build of course.
I agree it's better to be clear in compatibility: we don't support coroutines in the current distribution and use threads for Fibers.
But there is nothing fundamentally impossible here.

from truffleruby.

chuckremes avatar chuckremes commented on July 29, 2024 1

Thanks for your responses.

My use-case is related to celluloid and other programming libraries that hide asynchronous behavior behind a Fiber-based synchronous interface. At times there can be hundreds or thousands of fibers utilized by the libraries, so lightweight fibers are useful in that regard.

I would like to use TruffleRuby for a few proof-of-concept projects. I will likely need to implement some kind of fiber pooling mechanism to prevent run away thread allocation. If I discover anything interesting, I'll be sure to share it with you all.

from truffleruby.

eregon avatar eregon commented on July 29, 2024

Currently TruffleRuby uses Java threads for Fibers.

The standard JVM does not yet support native coroutines.
However, Lukas Stadler made a patch to add native coroutine support (http://ssw.jku.at/General/Staff/LS/coro/).

I am using that patch in my Oz language implementation.
The patched JVM is at https://github.com/eregon/jvmci and the corresponding API in https://github.com/eregon/truffle/tree/coro, which uses threads or coroutines depending on the JVM it runs on.

So we might use that to try what would be the benefits of native coroutines, but it is unpractical as it requires a custom JVM build.

Do you have any particular library or application in mind where it is important to have lightweight Fibers?
Thread switching is not so much slower, but they use more memory.

from truffleruby.

chrisseaton avatar chrisseaton commented on July 29, 2024

This is documented in our compatibility document. I've updated it a bit to say some more about fibers.

https://github.com/graalvm/truffleruby/blob/9d3a8f3e9f47915a0e4167e1002960a70b68f44b/doc/user/compatibility.md

Fibers, continuations and coroutines are all things that fundamentally don't match the execution model we are using at the moment and are unlikely to every be implemented with the same performance characteristics as MRI.

It's a shame, but it's one of a very few hard compatibility limitations we have.

from truffleruby.

chrisseaton avatar chrisseaton commented on July 29, 2024

To clarify, when I say 'fundamentally doesn't match our execution model' I mean running on an unmodified JVM. Benoit is talking about things which may be possible with modified JVMs or the SubstrateVM.

from truffleruby.

eregon avatar eregon commented on July 29, 2024

FWIW reusing FIber threads is something relatively easy, just not done currently in TruffleRuby (patch welcome!).
https://github.com/eregon/truffle/blob/247496f4984d9f08775f165cd7538a6d4c0dd90b/truffle/com.oracle.truffle.coro/src/com/oracle/truffle/coro/ThreadCoroutineSupport.java#L108

from truffleruby.

eregon avatar eregon commented on July 29, 2024

For information, Fibers now use a thread pool, so the cost to create many of them should be much lower.

from truffleruby.

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.