TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Compile and Run C in JavaScript

92 pointsby ekosz8 months ago

10 comments

Jarred8 months ago
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
评论 #41584226 未加载
评论 #41601242 未加载
评论 #41587894 未加载
评论 #41584309 未加载
seveibar8 months ago
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&#x2F; C: 6.0413ms Node: 5.1307ms C only: 4.3ms (+- 1ms)<p>I&#x27;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:&#x2F;&#x2F;github.com&#x2F;tscircuit&#x2F;bun-ffi-benchmarking">https:&#x2F;&#x2F;github.com&#x2F;tscircuit&#x2F;bun-ffi-benchmarking</a>
russfink8 months ago
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?
评论 #41587594 未加载
vlucas8 months ago
Great feature from the Bun team.<p>It&#x27;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:&#x2F;&#x2F;www.facebook.com&#x2F;notes&#x2F;10158791323777200&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.facebook.com&#x2F;notes&#x2F;10158791323777200&#x2F;</a><p>An article from Zend in 2011 about how to write a PHP extension in C:<p><a href="http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20110222035803&#x2F;http:&#x2F;&#x2F;devzone.zend.com&#x2F;article&#x2F;1021" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20110222035803&#x2F;http:&#x2F;&#x2F;devzone.zen...</a>
spacedcowboy8 months ago
The Objj compiler is pretty similar to this in Cappuccino and you get (pretty much) Cocoa bundled with…<p><a href="https:&#x2F;&#x2F;www.cappuccino.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cappuccino.dev&#x2F;</a>
评论 #41594356 未加载
评论 #41591951 未加载
pjmlp8 months ago
For me this looks like a solution for a problem that really isn&#x27;t there.<p>Anyone that cares about compiling C code should be skilled enough to actually use the right tools in first place.
评论 #41592043 未加载
mati3658 months ago
Lmao, I was first: <a href="https:&#x2F;&#x2F;github.com&#x2F;Mati365&#x2F;ts-c-compiler">https:&#x2F;&#x2F;github.com&#x2F;Mati365&#x2F;ts-c-compiler</a>
maidh918 months ago
How fast it is when comparing to bare runtime?<p><a href="https:&#x2F;&#x2F;github.com&#x2F;holepunchto&#x2F;bare-abort">https:&#x2F;&#x2F;github.com&#x2F;holepunchto&#x2F;bare-abort</a> or <a href="https:&#x2F;&#x2F;github.com&#x2F;holepunchto&#x2F;bare-buffer">https:&#x2F;&#x2F;github.com&#x2F;holepunchto&#x2F;bare-buffer</a>
gyutff8 months ago
Is this local js only or can you compile the c code and serve it to a client to execute in the browser?
评论 #41587948 未加载
knighthack8 months ago
...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.
评论 #41594454 未加载