You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • what are "Short" variable names?

    Good spot :) I'll update the docs, but it's max 4 characters. Any more and another variable will be created (which will get you up to 16 characters), and more means another variable, and so on.

    So if you keep your function names and variable names at 4 characters or less, you may see some improvements even without minification...

    Is there any benefit (or overhead!) in having all functions against the objects prototype?

    At the moment, there is... This is related to your question about defining functions inside functions.

    The problem with putting one function inside another is that because Espruino preserves the text inside the function, it's actually got one copy of the function as text, and then another copy as an actual function when the code is executed.

    Even if you delete the reference to the original function, I believe it will still be referenced from the functions that were defined inside it, so it won't get removed.

    So defining in the prototype uses a few more variables, but the actual text definition of the function is thrown away after the function is put in the prototype so you end up saving space.

    It's something I have plans to fix in the future, by implementing function hoisting which would scan a function (on definition) for the functions defined inside it, and would then pull them out as separate variables. It's a bit of a pain though, because Espruino would have to reconstruct what the code when it had to convert the function to a string :)

    So I'm afraid for the moment you're a bit stuck. At some point I have to stop using the online closure compiler for minification, and stick one inside the Web IDE. When I do that then I'd really like to use something that understood about modules, and could actually optimise over that boundary (removing functions that weren't being used and shortening all names). If anyone's got any ideas about that then I'd love to hear them though :)

About

Avatar for Gordon @Gordon started