-
I am currently working on porting an existing JS code base into ESP32 using Moddable. The code base is in TypeScript and was originally running on a NodeJS server. I spent two days refactoring the code to make it "platform plug-able" and now the same code is running on both NodeJS and ESP32!!! However I found the boot time suddenly becomes unacceptable slow, here is the boot log:
After logging "No Wi-Fi SSID", there is a delay of approximately 20 seconds before the first line of the application is executed. Through experimentation, it appears that this delay is closely related to the amount of code imported and used by the program. However, it is uncertain whether this delay is related to the specific files being imported or the functions being utilized. And yes, we have approximately 10,000 lines of auto-generated TypeScript code that manages communication protocols. I've noticed that the size of the image remains unchanged even when I add or remove references to the large file (which is around 2MB in size).
ased on my understanding of the XS engine, having a large code base should not be an issue since the byte-code is stored and executed in ROM. In fact, according to the documentation: I would greatly appreciate it if someone could kindly point out anything that I may have overlooked. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Good morning! Congratulations on getting such a large code base shared between the two environments. It isn't 100% obvious what might be causing the slow down here. Let's try to figure it out. The delay is after the virtual machine is instantiated. We know that because the "No Wi-Fi SSID" message is logged by setup code that is implemented in JavaScript. That helps to limit where we need to look.
This sentence is preceded by a discussion of preloading by the XS linker: "The XS linker constructs all built-ins and preloads most modules..." PreloadingIf your modules are not being preloaded, they will still take some time to instantiate. That time is less than compiling the source code to byte code (the byte code is already stored in ROM) but can still add-up. xsbug is a great way to check which modules are preloaded. Set a breakpoint at the start of your main.js. In xsbug, look at the "modules" panel. The modules that are preloaded are displayed in blue, those which are not preloaded are displayed in black. Here you can see that here helloworld all the Moddable SDK modules (time, timer, Resource, etc) are preloaded and only main.js is not: The preload documentation describes in detail how to preload modules. Not every module can be preloaded, but most can be (nearly all modules in the module SDK are). ProfilingThe profiler is a useful tool for understanding where time is being spent. There's an introduction to the profiler on our blog and more detailed profiler documentation on the implementation and interpreting the results. You can start/stop the profiler dynamically through the UI. There is also an option to start profiling when the VM is created. In this case, that might be your best choice. That's controlled in xsbug preferences: Let's see what you find by investigating preload and profiling. We can continue the investigation from there. |
Beta Was this translation helpful? Give feedback.
Good morning!
Congratulations on getting such a large code base shared between the two environments. It isn't 100% obvious what might be causing the slow down here. Let's try to figure it out.
The delay is after the virtual machine is instantiated. We know that because the "No Wi-Fi SSID" message is logged by setup code that is implemented in JavaScript. That helps to limit where we need to look.
This sentence is preceded by a d…