This was an unplanned feature I worked on mostly a month ago on a Saturday for fun. Happy to answer any questions<p>To get it out the door, ended up adding some patches to TinyCC to support .framework on macOS and fix a few things with dlopen and include paths. Also added support for parsing the deprecated attribute used in lots of Darwin headers. C parsers seem a lot simpler than JavaScript which is nice
I ran some benchmarks and got about a 10% improvement by porting a simple function used in autorouting to C. With the subfunction ported to C, Bun was still ~15% slower than node (v8). As the article hints at, you probably need to port fairly large subfunctions to see major performance gains. Results:<p>Bun: 6.7410ms
Bun FFI w/ C: 6.0413ms
Node: 5.1307ms
C only: 4.3ms (+- 1ms)<p>I'm generally very bullish on Bun and was very happy with the DX for this C api. Great work to Jarred and the team!!!<p>benchmark code: <a href="https://github.com/tscircuit/bun-ffi-benchmarking">https://github.com/tscircuit/bun-ffi-benchmarking</a>
I wonder about the security of this. Are programs executed in some kind of jail? Is there a limit to certain features, e.g., opening a socket to somewhere?
Great feature from the Bun team.<p>It's worth noting that similar functionality is what allowed PHP to be useful well beyond its original capabilities when companies hit scale and needed more performance out of it. Companies would just write a C module for their critical path code, and load it in as a PHP extension.<p>An article from Facebook in 2010 about them writing and using a custom C extension for PHP, that was probably the precursor to JSX:<p><a href="https://www.facebook.com/notes/10158791323777200/" rel="nofollow">https://www.facebook.com/notes/10158791323777200/</a><p>An article from Zend in 2011 about how to write a PHP extension in C:<p><a href="http://web.archive.org/web/20110222035803/http://devzone.zend.com/article/1021" rel="nofollow">http://web.archive.org/web/20110222035803/http://devzone.zen...</a>
The Objj compiler is pretty similar to this in Cappuccino and you get (pretty much) Cocoa bundled with…<p><a href="https://www.cappuccino.dev/" rel="nofollow">https://www.cappuccino.dev/</a>
For me this looks like a solution for a problem that really isn't there.<p>Anyone that cares about compiling C code should be skilled enough to actually use the right tools in first place.
Lmao, I was first: <a href="https://github.com/Mati365/ts-c-compiler">https://github.com/Mati365/ts-c-compiler</a>
How fast it is when comparing to bare runtime?<p><a href="https://github.com/holepunchto/bare-abort">https://github.com/holepunchto/bare-abort</a> or
<a href="https://github.com/holepunchto/bare-buffer">https://github.com/holepunchto/bare-buffer</a>
...So is this a transpiler of some sort?<p>If it is, consider looking in Nim. It compiles to C, and even compiles to Javascript. And is extremely performant while at it.