13 ms·
LLJS: Low-Level JavaScript
- m0skit0 14y agoI don't see what benefits this has C doesn't... maybe someone will see them. Anyway cool idea and runs flawlessly in Firefox 15.0.1@Ubuntu 12.04.
- andreasvc 14y agoDoes C run in Firefox? No? Well there you have your benefit.
- billwashere 14y agoHow about emscripten then? https://github.com/kripken/emscripten https://github.com/kripken/emscripten *Not that I would.
- andreasvc 14y agoWell that seems to be a competitor. If you'd asked me the benefit of emscripten over this I wouldn't have known, but the question was about C.
- mbebenita 14y agoThe benefit over Emscripten is that LLJS makes it easier to mix JS and C-like code and skip the C/C++ tool chain. Of course, the drawback is that you miss out on all the LLVM optimizations.
- agentultra 14y agohttp://www.cs.cornell.edu/home/ulfar/cuba/paper/ http://www.cs.cornell.edu/home/ulfar/cuba/paper/ Any language could. Javascript's ubiquity is just an accident of history. Nobody planned for it to be this way. It's not even the best way. Why not a C applet in the browser with access to native hardware? Let the OS handle access to memory and system call interception. Why not CL? Or Python? Or anything else? Why do we have to let JS continue to be the de facto language and tack on all of these monstrosities upon it?
- mbetter 14y agoYou get on that, let me know how it turns out.
- andreasvc 14y agoAn important reason is security. The security of any web language is of vital importance, for obvious reasons. When you go low level or introduce umpteen different languages, maintaining the same level of security becomes increasingly challenging. But I agree with you that JS is an unfortunate language to be stuck with (although many people appear to be content with it). I especially dislike that it's weakly typed. Isn't Google's NativeClient something like what you're suggesting though?
- agentultra 14y agoI'm not suggesting anything, the paper I linked just described one such method for executed untrusted binary code through the browser. At a cursory glance it looks like NativeClient is built on a sandbox and doesn't allow arbitrary binary applications to run natively on the OS. It doesn't allow system calls and looks like some sort of run-time manages memory on behalf of the application. If you're at all interested, it cannot hurt to read the paper I linked to. It was written in 1997 and requires a little bit of historical forgiveness but the ideas are rather quite interesting.
- LnxPrgr3 14y agoGoogle's already on it: https://developers.google.com/native-client/ https://developers.google.com/native-client/ Some part of this seems unsafe intuitively, but then I'm reminded sandboxed interpreted languages don't have the best security track record either.
- pav3l 14y agoJavascript can run in the browser, distributed computing. http://hackaday.com/2009/03/03/distributed-computing-in-javascript/ http://hackaday.com/2009/03/03/distributed-computing-in-java...
- deleted 14y ago[deleted]
- suprememoocow 14y agoOh dear. The site immediately crashes Chrome (Version 22.0.1229.79 m) on Windows XP.
- zapu 14y agoSame here. Also Chrome and Windows XP. But it manages to load after few refreshes. But I can't run any of the "demos".
- terinjokes 14y agoWorks fine in Chrome 23 on Mac.
- markus2012 14y agoWorks on version 24.0.1284.2 on my mac.
- overbroad 14y agoOxymoron.
- mlvljr 14y agoCurses!
- zx2c4 14y agoDespite my usual cynicism about #javascripthipster projects, this does actually look kinda neat. The one thing that rubbed me the wrong way is the "let" keyword. Why can't we just declare variables without it, like C does? I suppose because they want to rely on JavaScript's own scoping rules? What would be cooler would be if they could just totally do away with making actual JavaScript variable declarations or function calls, save for the set of typed arrays, pushing and popping variables on and off the stack for function calls, and then coming up with some horrible hack for implementing jmps in a language with no goto. I'm sure this wouldn't really make things more efficient, but it'd be interesting to read. I guess though, there's always the source of emscripten for that delight.
- dasil003 14y agoThis is more of a #javascriptneckbeard project for which I have to give a healthy respect.
- mbebenita 14y agoRelying on JS function calls and variable declarations is actually more efficient in this case since the underlying JS JIT can perform a lot of optimizations (SSA / Register Allocation). We do stack allocation for structs and local variables for which you need to take the addresses of. The "let" keyword is left in there because we wanted to stay compatible with JS. So any JS program is also an LLJS program. This way it would be easy to integrate into an existing code base. As for the "let" vs. "var" debate, we chose "let" because of its block scoping semantics and because we didn't want to let variable declarations alias each other with different types.
- rbanffy 14y ago> The one thing that rubbed me the wrong way is the "let" keyword. Reminds me of 8-bit BASIC. Without the line numbers.
- Ygg2 14y agoRunning examples on Chrome with Win 7 crashes the tab. It's not that big deal, but for now other than a neat way for crashing your browser I don't see any application for this framework/library.
- sitkack 14y agoCrashes iPad 1 with iOS 5.1
- akadien 14y agoHalf of the web seems to crash iPad 1 these days.
- hellrich 14y agoNot enough RAM.
- brooksbp 14y agoNearly all of the web crashes my iPhone 3G.
- dugmartin 14y agoI've stopped clicking on Techcrunch links here on my iPad 1. If I do click through I get a page load, then a half page repaint, then the browser going white, then a page load, another half page repaint and then a browser crash. Maybe it is a feature?
- lucian1900 14y agoThis is actually pretty interesting. Some of the performance benefits of C (known types, little and predictable allocation) without its total lack of any safety. Syntax still sucks, but not much can be done about that while still looking like JS. On the other hand, any runtime that infers structure (like V8 or PyPy) will make most of the performance benefits moot, leaving only predictable allocation (fewer and shorter GC pauses).
- tomp 14y agoThe syntax doesn't matter; if the browsers implement something like this, it will make javascript a much more compelling target for compilers (even of fast, statically typed languages), so you can make your own syntax above it!
- lucian1900 14y agoI meant that the syntax still has plenty of pitfalls. Compilers can already uses the same features lljs is using and just generate JS.
- dllthomas 14y agoOne way in which it might actually help significantly is if it motivates coding in ways that are better structured, and the sophisticated run-times can take good advantage of this.
- davvid 14y agothis keeps crashing my golden oldy iOS device. it must be webkit since others are getting chrome crashes too.
- dugmartin 14y agoImmediate crash for me too on my iPad 1 with iOS 5.1.
- mgaudin 14y agoSame here. Crashes for Windows 7 Chrome Version 22.0.1229.92 m
- jhrobert 14y agoCool. This leverages JIT compilers ability to generate fast code (at the expense of language expressiveness, for it obviously works well with static style code only). I wonder what a "JavaScript JIT optimized C dialect" would be? Ie. what are the C mechanisms that are too expensive with today's JIT engines?
- deleted 14y ago[deleted]
- djhworld 14y agoNice. For now, we allocate one large chunk of memory 32 MB and let malloc and free manage it. 32mb sounds like a lot
- mbebenita 14y agoThe size can be adjusted to whatever size you need. In principle this can be done automatically by malloc by hot-swapping the typed array with a larger one.
- pkolaczk 14y ago32 MB of heap is not any problem for modern GCs and modern RAM speeds. With a typical DDR3 memory with bandwidth of 16 GB/s that should fully GC in a few ms. And good GCs usually don't stop the mutator in the marking phase (at least so do some GCs in Java), so the total blocking time could be even lower.
- bdittmer 14y agoBuild a single page javascript application and don't refresh after using it for a few hours. I've yet to find one that doesn't leak memory like a sieve.
- achille 14y agoThe render process on very page you're on right now consumes 116mb, see: http://i.imgur.com/gCA1C.png http://i.imgur.com/gCA1C.png
- haldean 14y agoAre you on a Retina display? That screenshot is beautiful (and huge).
- p0nce 14y agoNeat but the target language does not seem like regular Javascript.
- judofyr 14y agoEhm, it's valid JavaScript. What is not "regular" about it?
- djhworld 14y agoHe probably meant to say "readable"
- evincarofautumn 14y agoGenerated code rarely is. The compiler I maintain at work had “readable output” as one of its early goals. That was abandoned around when we started adding optimisations.
- zumosol 14y agobenchmark: time for the loop with signed integers: lljs = 116 ms, sbcl = 0.026, so lljs is still five times slower than sbcl in my computer (64 bits, ubuntu). Compiled in: 32 ms ----------------------------------------------------- Timer: 116 ms: Empty For loop with signed integers. Timer: 604 ms: Empty For loop with unsigned integers. Timer: 115 ms: Empty For loop with untyped integers. ----------------------------------------------------- Executed in : 835 ms. (time (loop for i fixnum below 50000000 do (progn nil))) Evaluation took: 0.026 seconds of real time 0.028001 seconds of total run time (0.024001 user, 0.004000 system) 107.69% CPU 53,460,529 processor cycles 0 bytes consed NIL
- djhworld 14y agoCan any javascript people explain this piece of code const $M = require('memory'); That the compiler outputs as JS? Is the 'require('memory')' something that is native to the JS runtime?
- mbebenita 14y ago"require('memory')" gives you back a JS module that's written in LLJS (http://git.io/vHeH2g http://git.io/vHeH2g). It exports several typed array views and a few functions like malloc() / free(). It's all JavaScript, nothing native.
- error54 14y agoCrashes tab on load. Chrome 24.0.1284.2 on WinXP.
- yalogin 14y agoI don't work with JS. Can someone explain to me how I can use it as a developer? Should I be writing code in the intermediate representation and then compile it into JS?