[ COMPILER MESSAGE ] : Error: Infer(unforced) kept changing stuff #6670
Replies: 1 comment
-
Posted at 2023-01-10 by @fanoush Nowadays using new "jit" feature may be good enough to speed things up, can you try replace BTW it is just a warning, does it not work? you can try replacing the Posted at 2023-01-10 by @fanoush BTW did you check https://www.espruino.com/Compilation sections "Caveats" and "Doesn't Work"? Also the "How do I use it?" shows type of code that makes sense to use with "compiled" - tight computational loops, hardware access. it is not worth it for random generic js code. Also beware that you cannot distribute your app in sane way, it probably won't work at all with the bangleApps loader. There is workaround for small bits of Inline C, see Posted at 2023-01-10 by BillV Thanks @fanoush. The error from "compiled" stops it working and the code is just uploaded as source. I have other problems with "jit": it seems not to like '&&' both on the line in question and elsewhere in my code:
The following test gives me the same error:
I do have many maths options in a loop: I'm making a version of https://www.youtube.com/watch?v=IA4UsV04bnM and am rotating 128 lines - there's a couple of screenshots below. I've tried to optimise the code anyway by precomputing the rotated lines, using Int8Arrays and Float32Arrays etc. What's left in the loop is therefore pretty simple arithmetic, indexing into the arrays and comparisons but quite a lot of them. Without compiling I get roughly 1 loop per sec, with I get between two and three per sec so a really good improvement. Attachments: Posted at 2023-01-10 by @fanoush OK, can you show whole method you are trying to compile? it is worth to restructuring it so only the computational part is inside "compiled" and the code mostly looks like pure C. You may also consider Inline C which produces much smaller and faster code and is easier to distribute. InlineC is not easy when you need to call into JS methods or use JS variables but for passing data in/out there are workarounds with passing flat array pointers. Recently I tried to use "compiled" code and basically I only took the result of the compiler as inspiration and used it directly inside Inline C. Also I needed to hack the compiler to not to hardcode value of EXPTR inside the binary so it can work across different build versions. Posted at 2023-01-10 by BillV Sorry, I meant to say that I had looked at the page on compilation and noted the warnings although I hadn't realised that the loader wouldn't work. I'm still some way off being able to distribute the code, though! Posted at 2023-01-10 by @fanoush I think the best way is to use If the performance in not good enough I'd use Inline C by doing the math inside native method with just data passed in/out.
In my case I wanted to code SWD protocol in pure JS. After prototype which is available here https://github.com/fanoush/EspruinoBoards/blob/master/STLINKV2/swd.js I tried to use Posted at 2023-01-10 by BillV Many thanks for your help and I'm happy to follow your guidance about "compiled". I'll have a further look at jit and see if I can get that working. Posted at 2023-01-11 by @gfwilliams Hi, That clock face looks amazing! As @fanoush said, I think probably the best thing is to look at using If you change:
Then it looks like that'll fix it. It'll be some issue with the compiler having trouble figuring out the type of Right now as you mention Definitely just try and pull out only the bit of code that needs to run fast and jit/compile that, and don't do anything that doesn't need it. I know the temptation is just to slap Posted at 2023-01-12 by BillV Thanks, @gfwilliams. i'm afraid I'm still struggling: another line in my program contains:
which gives the same error. I've tried adding parentheses as in your suggestion, eventually ending up with abominations like
but all these variants gave the same error. Frustratingly, just including the offending line in a simple test program works perfectly so the problem must be due to something elsewhere in the code. I will try to sort it out. I'm afraid I've been doing exactly what you and @fanoush warn against, sticking "compiled" on the entire draw loop. This runs at 5 frames per second versus about 1.5 for raw or vanilla. So while I don't want ignore your advice , I'm loathe to give up the extra speed - it will be interesting to see what JIT delivers when I can get that working. My use of the watch is entirely focused on interesting watch faces - I have very few other apps installed so RAM usage and startup speed aren't really issues. I would like to contribute something to the community, however, so when I have this face working properly I hope to publish it. Posted at 2023-01-12 by @fanoush
There are two issues
Posted at 2023-01-12 by BillV Thanks @fanoush, shows how well I know Javascript! Much appreciated, I hope I can now fight it to a standstill. Posted at 2023-01-12 by @fanoush maybe with numbers beware that bitwise and may not behave exactly as &&, see
Posted at 2023-01-13 by @gfwilliams
I think you may find that you don't actually end up losing much speed at all. Espruino's not that much slower than compiled/JIT when it comes to simple function calls - it's more when you get to loops and calling the same stuff over and over that it's not so great. Also while doing everything might be marginally faster, it's likely to be a lot slower at boot time when the compiled code has to be loaded into RAM from flash... So you're likely to make life a lot easier for yourself if you can figure out which bits are taking time and optimise just those :) One thing to add which might really help you - I guess you're using Posted at 2023-01-14 by BillV Thanks, both. The comparisons are working in line with @fanoush's guidance and I'd already bound calls to Math.xxx, I will bind g.xxx as well - I will get there eventually! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-01-10 by BillV
I'm trying to compile a watch face that includes the following code to change the background colour as a simple low battery warning:
When compiled this gives:
If the line is commented out the warning doesn't appear and the compiled version runs.
What causes the error and is there a way around it? Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions