Espruino speed improvements - compiled JavaScript? #405
Replies: 67 comments
-
Posted at 2014-12-19 by Loop Sounds great, I hope I may be able to give it a try during the weekend! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-19 by DrAzzy Oh cool! Very interested to see how that goes. I think it would be key to figure out what sort of JS ought to be compiled like that, and which stuff shouldn't be. There'd need to be some way to tell it to compile or not compile a piece of code. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-19 by @gfwilliams If the first statement is a string saying "compiled", it'll have a go at it. It's pretty basic :) I got a bit carried away... If you now do:
it's compiled to:
which is then assembled to:
It still needs a lot of work - like getting the function pointers for |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-19 by DrAzzy This is super exciting. The Espruino has always been a hybrid of native code and JS, but this makes the native code side much more accessible, and gives us a way to address the cases where speed actually limits us on the Espruino. Where does it put the compiled code? It looks like... just after the end of the stack. Isn't that where the last JSVars go? It sounds like you'd need to also reduce the number of jsvars by ceil((ASM_BASE+/16) when the compiled code is uploaded, otherwise, if it uses the last jsvar, it'll trash the compiled code. Also raises the question of how to save() these, though that might not be hard if they're stored in the same area as jsvars. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-19 by @allObjects This is really cool... since you know the guts, interfacing between compiled and interpreted can be very optimal (and programmer transparent). It is like REXX (on main frames and os/2) did as well as IBM's/OTI's Smalltalk... which compiled to the actual hardware and hid it within the actual file as property or loaded only the JIT stuff. Since JIT on espruino is not an option, why not doing it by the IDE on upload onto the board... I hope that referencing still goes through the JS-specific 'very late' binding... than there is no reason why js and compile js can not work in coexistence... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-19 by @gfwilliams At the moment the assembler is at the end of the stack (it grows down) - so adding more code reduces the amount of recursion - but not the amount of variables. In 1v72 I actually added the ability to have continuous blocks of memory via ArrayBuffers, so putting assembler into the variable space would be fine now, and would allow everything to be saved. It's something I'll hopefully add soon. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-20 by @gfwilliams Another update. It now actually does stuff...
Compiles to:
Which does:
I doubt I'll get much more time to work on it over christmas, but it's looking very promising indeed. Needs a lot of tidying, and I've got to add calls to |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-20 by @gfwilliams
gives:
And that's just the start... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-24 by @gfwilliams One more:
So locking is now sorted and this is powerful enough for while loops - for instance for the mandelbrot fractal. There's some minor glitch with the maths but it looks very promising. Interestingly this still isn't super fast because of the variable lookup, but that's something that will change soon too! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-27 by JumJum I love the option to precompile functions.
Christmas is gone, but sometimes wishes come true later too..... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-27 by Glocke I think , from my personal point of view , this is one of the few things missing Espruino . The speed , compilation and/or pseudocode/asembler generation that are key to success of Espruino . Most functions that are programmed in a microcontroller pro/hobby, like a leds, some analog readings on these calculations, etc ... every 100ms or a reasonable time, do not penalize the overall implementation of these "events" , but if we add too many other low priority process, over a others CPU-time with the run-time-compilation, and if the project is complicated , it can penalize both implementation and memory usage. The compilation before flash, and the generation of ByteCode (outher o inside microcotroller), is great! I encourage you dig splendid views to ELUA project (http://www.eluaproject.net/overview/status). A "languaje script " based on Lua, very mature, and where use of compiling and generating ByteCode done, even when the "source code" ( script ) is stored in Flash memory or a SDCard, less flash memory usage, better speed and low RAM. Lua like a language, I do not like too much. I prefer Javascript. See Cross-compiling at http://www.eluaproject.net/doc/v0.8/en_using.html Thank you for this fantastic tool. You encouragement to proceed further in this line ( ByteCode / compilation ) because I believe that is the only (or can be a) problem for Freduino. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-28 by @allObjects @jumjum... more Christmas-es to come... and many worth-while events in between: Man muss die Feste feiern wie sie fallen! ;-) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-29 by @gfwilliams @jumjum, the 'automated build' actually builds all commits in all branches, so for instance if you look on https://github.com/espruino/Espruino/tree/js_compiler you'll get the commit hash cca740699928e7f5ee1cee62e43299e19b33f10f, which you can then use as the URL, eg: http://www.espruino.com/binaries/git/commits/cca740699928e7f5ee1cee62e43299e19b33f10f/ If you try that build, you should be able to get the compiled code in the Web IDE to work with it. Thanks for the other discoveries too - I knew when I wrote the code that I should have tested it with two compiled functions :) The real killer thing for this will be the new 'setWatch' functionality which allows you to run code in an interrupt. Unfortunately there are some issues with accessing JavaScript variables directly from an IRQ, but hopefully I can overcome those with a bit of work. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-30 by JumJum Thanks to your hint, I got it running, firmware and compiler. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-12-31 by @gfwilliams That's odd - that code has been working for ages. And you're connecting over USB? It could be that the timeout for reading it is too short on some computers? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-11 by @gfwilliams You could step back in the command history (up-arrow on left hand side) to find the code that was sent, and could copy that... At some point I'll post some code up to allow you to manually compile C functions with Linux+GCC. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-11 by Uhv Ok, I have extracted a code of simple function from the board. But the procedure is not very transparent... And how will it look for more complex function?.. But how can I compile a JS code for Espruino by myself? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-12 by @gfwilliams It'll look the same for a more complex function - there'll just be a bigger string of characters. To compile it yourself you'd have to check out https://github.com/gfwilliams/EspruinoCompiler and run your own server. However I'm not quite sure why you can't just use the Web IDE (or command-line tools) to compile and upload code yourself? The compiled code will only work with the version of Espruino it was compiled for, so if you update you'll have to change everything. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-13 by Uhv Unfortunately I have an internet connection not always... And fact that I must compile a code again for new Espruino version is not a good thing. Say please is it possible to run a compiled code from controller's flash? I'd like to save compiled functions to STM32's flash by STM32F1 FLASH MEMORY MODULE and call them from there. Or do the compiled code works from RAM only? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-13 by @gfwilliams Yes, you can manually save them to flash - but you'll still have to recompile them every time you update the firmware. To save them to flash, you'd have to copy the You can even save them to an SD card if you want. I posted about it here But I don't really see what that gets you given the need to recompile. If you don't have an internet connection, download and set up http://github.com/gfwilliams/EspruinoCompiler on your computer, then point the Web IDE at it. It'll then dynamically compile your code on your own PC. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-13 by Uhv Yes, it looks like I thought To save code to SD card is a good thing too, but it requires RAM for code that must be loaded. And if I have saved a code to controller's flash I can run it directly withoud loading to memory. Isn't that so? Ok, I will probe to compile by myself. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-13 by @gfwilliams
Yes, that's right. However compiled code really won't take that much of your memory. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-14 by Uhv I cannot run node server.js :-( It writes "Error: Cannot find module 'acorn' ". Where can I load it from? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-15 by @gfwilliams
You might need to do that with some other modules too. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-15 by Uhv I understand nothing... I have installed acorn module like you had said, it has written that it was installed in a folder that I have set in system variable path, but node doesn't see it and writes: "Error: cannot find module 'accorn'". What do I not correct? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-15 by @gfwilliams I have no idea I'm afraid - it worked when I did it... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-15 by Uhv Very interesting... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-15 by Uhv I had copied the node_modules with installed acorn from the npm's folder to catalog ..\EspruinoCompiler-master. The error went away, the server runs (in browser at the address localhost:32766, I see the the message Espruino compilation server), but compiling isn't performed :-( The function is sended to Espruino as javascript code, not as native code |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-18 by @gfwilliams Did you change the address that's in the Web IDE's settings? Also, you'll have to have installed GCC for ARM... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-05-18 by Uhv Yes, sure. I have changed the Javascript Compiler address in Web IDE. The GCC for ARM is installed, but I have no idea how it must be attached to JS Compiler. I think problem is that JS Compiler doesn't see the GCC... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-12-19 by @gfwilliams
Not sure if anyone's interested, but I came up with a way of doing a kind of 'JIT' compilation of JavaScript inside the Web IDE (it work the same way inline assembler does at the moment).
I posted an 'issue' and a very hacky branch for this up on GitHub. It's not usable at the moment but I'd be interested to see what everyone thinks about it:
espruino/EspruinoTools#4
I thought it'd be a nightmare, but it looks like it'll be possible to get a useful subset of JavaScript compiled quite easily.
Beta Was this translation helpful? Give feedback.
All reactions