Open Bug 757804 Opened 12 years ago Updated 2 years ago

Investigate reimplementing some of ctypes in JavaScript

Categories

(Core :: js-ctypes, enhancement)

enhancement

Tracking

()

People

(Reporter: Yoric, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

I have the impression that a sizeable chunk of CTypes.cpp could be ported to JavaScript. More precisely, I have the gut feeling that pretty much only the following cannot be ported to pure JS:
- finalizations;
- actual function calls through libffi;
- constants and size of a few types.

If we can indeed port a chunk of CTypes.cpp to JS, this bring the following gains:
- finer error reporting, with the ability to refine it further;
- better JIT-ability;
- easier to extend and to attract contributors.
This looks like a good internship project, btw.
Attaching 20 minutes of work on the topic. I have the impression that we can do at least most of CType/CData in JavaScript. If there is any interest, I can try and continue work on the topic as a background task.
Attachment #626822 - Flags: feedback?(jorendorff)
Attachment #626822 - Flags: feedback?(dwitte)
I have opened a github project for this experiment: https://github.com/Yoric/js-js-ctypes .
I have made some progress on this experiment. This seems to confirm that most/all of CType/CData can be written in JS, with two C-based operations implementing & and *. I believe that both operations could be trivially JIT-ed.

Now, the interesting part is that the code for conversion of data from/to C, with the exception of strings, is pure JavaScript, hence can be JIT-ed without any change to the JIT. Also, this code is, for the moment, more readable than CTypes.cpp, which is a gain.

I will post further updates as they arrive.
Attachment #626822 - Flags: feedback?(jorendorff)
Taras, given that I have some time waiting for reviews, do you want me to take a further look at this bug? Given the measurements on bug 873307, I suspect that this could help improve performance of js-ctypes calls.
Flags: needinfo?(taras.mozilla)
(In reply to David Rajchenbach Teller [:Yoric] from comment #5)
> Taras, given that I have some time waiting for reviews, do you want me to
> take a further look at this bug? Given the measurements on bug 873307, I
> suspect that this could help improve performance of js-ctypes calls.

No. I think working on zero-copying strings/objects to workers is higher priority. I think you should help with that instead.
Flags: needinfo?(taras.mozilla)
Comment on attachment 626822 [details]
First draft of something

Clearing stale request, sorry -- I'm sure there are better qualified people to look at this if you're still interested in pursuing it :)
Attachment #626822 - Flags: feedback?(dwitte)
This looks very interesting!

(In reply to David Rajchenbach Teller [:Yoric] (please use "needinfo?") from comment #3)
> I have opened a github project for this experiment:
> https://github.com/Yoric/js-js-ctypes .

I understand the code, but I think I need more time to understand how the code in C++ library maps to the JS you wrote. Lets talk about this on IRC? I can do this for my project this semester :)
Flags: needinfo?(dteller)
Actually, all of this will be much easier once bug 578700 has landed, so we should wait for that.
Flags: needinfo?(dteller)
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: