Comments (9)
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.
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.
Thanks you for your detailed response.
from janet.
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.
Perhaps a mailing list would be better?
from janet.
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.
Gitter seems a good choice.
from janet.
I have started a Gitter channel here, hopefully this is easier than IRC.
from janet.
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)
- Error stating 3 is not an integer? HOT 3
- if-let macro behavior changed? HOT 3
- After a stream is created ev/sleep takes 100% CPU. HOT 4
- Support a cosmopolitan target HOT 6
- error: cannot marshal fiber with c stackframe HOT 2
- (default) not working HOT 6
- Cannot load native module with MinGW (GC error) HOT 9
- Splicing a tuple into an indexed literal causes subsequent form to compile incorrectly HOT 4
- `os/rename` behaves differently on Linux vs Windows HOT 2
- (doc next) doesn't mention fiber HOT 1
- Potential arity check bug in peg.c HOT 4
- Bugs when cancelling a waiting fiber HOT 5
- Advent of Code, day 7 - non-deterministic output
- macex raises on () HOT 8
- segfault can result if `net/server`'s handler has incorrect arity
- `ev/deadline` and `ev/with-deadline` should be documented better. HOT 1
- (some) returns first truthy predicate result, not first truthy item HOT 6
- let* please, possibly even letrec, letrec* HOT 4
- janet fails to run with 'error while loading shared libraries' HOT 7
- Improve sandboxing to allow more granular permissions HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from janet.