An Introduction to JS-Ctypes

Sam Tobin-Hochstadt samth at
Sat Sep 17 06:14:36 PDT 2011

On Sat, Sep 17, 2011 at 4:12 AM, Andrea Giammarchi
<andrea.giammarchi at> wrote:
> my thoughts, my benchmark, and my worries about StructType and
> ArrayType:

This blog post is confusing 3 different things, and thus coming to
wrong conclusions:

1. Binary Data, a spec for handling bit-level encodings of various
values.  This is related to Typed Arrays, another spec that's shipping
already in some browsers.

2. js-ctypes, which is a foreign function interface for JS in Firefox.
This is used for calling host libraries using the native platform
(C-based) calling convention.  If you're coming from a python
background, it's very similar to, and named after, the 'ctypes'

3. Cython, a restricted dialect of Python that compiles to C for performance.

These are all totally different things.  Your blog post compares 2 and
3, and then draws conclusions about 1.  If you want to benchmark
js-ctypes against something from Python, you should benchmark it
against ctypes, although they both use the same underlying library,
libffi, so the results probably won't be that different.

There is currently no high-performance implementation of the Binary
Data spec, so it can't be usefully benchmarked at this point.  Typed
Arrays does have high-performance implementations currently.  There's
also no analogue of Cython of JS, because the JS implementation
community has focused on making fast implementations of all of
JavaScript, rather than limiting the language.

Finally, your use of the Function constructor prevents many
optimizations -- don't do that in JavaScript code that you want to be
high-performance.  There's an excellent overview of how to write
high-performance JavaScript code by David Mandelin here:

sam th
samth at

More information about the es-discuss mailing list