Giter Site home page Giter Site logo

Comments (9)

bakpakin avatar bakpakin commented on May 12, 2024 1

Just an update, I have just pushed some changes to the vm and janet_call that should make janet_call much faster. I was able to make janet_call use the current fiber and not create new fibers.

The changes are in 8a3f512.

from janet.

bakpakin avatar bakpakin commented on May 12, 2024

Side question : Is there a better way to ask such question than opening a "issue" ?

Check out the #janet IRC channel on freenode


Janet currently does have a bit of overhead going from C to Janet. This will shrink in the future but may never disappear entirely. When calling a Janet function from C, via janet_call, the vm needs to do some bookkeeping for safety reasons.

  • Create or reuse a fiber with the function.
  • Use setjmp to catch errors so resources aren't be leaked.
  • Update global state to point to the new fiber, mark it as a gc root, etc.
  • Enter the VM via the funciton run_vm in vm.c

Altogether, this accounts for some overhead. In the future, I plan on adding a pool for fibers so creating
new fibers will be very fast and is often just reusing old fibers. There are other optimizations that I have been considering that would also remove the need for some of these steps, such as having janet_call run on the current fiber and not create a new fiber at all. This can be difficult, however, as we want to prevent any possibility of resource leaks when extending the vm.

For now, I would not worry about the overhead as it should improve, and just stick to janet_call. I think there is a lot of room to improve the overhead without changing the API. There is also the function janet_continue which lets one resume a fiber, and janet_fiber_reset, which lets you take an old fiber and reinitialize it with a new function. These will be much less convenient than janet_call, though.

Other notes:

janet_unwrap_* do not check the type of their arguments. Use

if (janet_checktype(val, JANET_NUMBER)) {
  /* is a number */
} else {
  /* is not a number */
}

to check if val is actually a number. The janet_get* functions check their arguments and provide nice error messages.

from janet.

jfcap avatar jfcap commented on May 12, 2024

Thanks you for your detailed response.

from janet.

honix avatar honix commented on May 12, 2024

Sorry, I don't like irc as it doesn't save message history. I would better prefer to use issues for this kind of questions.

from janet.

bakpakin avatar bakpakin commented on May 12, 2024

Perhaps a mailing list would be better?

from janet.

bakpakin avatar bakpakin commented on May 12, 2024

I guess issues work for now, but Iā€™m not sure that discussion is what github intended them for. Keeping everything centralized on github is convenient though. Perhaps a chat service like gitter would work too.

from janet.

honix avatar honix commented on May 12, 2024

Gitter seems a good choice.

from janet.

bakpakin avatar bakpakin commented on May 12, 2024

I have started a Gitter channel here, hopefully this is easier than IRC.

from janet.

jfcap avatar jfcap commented on May 12, 2024

Indeed it's really faster.
My basic benchmark show a ~6X speed improvement !

Now the C version of transform function is 3 times faster then the janet version.
Well done.

from janet.

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.