Questions about the size limits of custom blocks

Issue #396 resolved
xixicarry created an issue

Hello, John! This is Yongyu speaking. We recently found that the script is too large to be burned on the motherboard, so we need to disassemble the script before it can be burned smoothly. I have consulted Wen Jie, and he said: I sent it to John last year, and John said that the size of a single custom building block was limited, so he suggested splitting it.

I'd like to know what the size limit is for custom blocks so that I can avoid this situation. Our developer checked earlier, and it looks like the limit is 1000.

In addition, our competition motherboard is developed based on ESP32, and it has 8MB of RAM. I wonder if we can expand the threshold to 3000 or above. I am also a little worried about whether enlargement will affect other links.

I hope you can give me a professional reply. I wish you all the best.

Comments (3)

  1. John Maloney repo owner

    Hi, Yongyu.

    You are correct, the compiled code of any single script cannot be greater than 1000 bytes. That is due to the need to buffer incoming scripts in RAM on boards that have very limited RAM, such as the ESP8266 and the original micro:bit.

    Increasing that limit would make it impossible to use MicroBlocks on those boards. We might consider making a fork of MicroBlocks that increases that limit. Doing that would break compatibility with the official MicroBlocks branch (i.e. projects with large scripts would not work in the unmodified MicroBlocks), but that may not be an issue for the programming competition.

    However, long scripts are harder to understand and debug than shorter ones. Thus, I encourage students who run into this script limit to refactor their code into several shorter functions.

    With "show advanced blocks" enabled, you can check the compiled code size of a given script by selecting "show instructions" from the right-click menu on the script:

    Screenshot 2023-05-22 at 6.32.36 AM.png

  2. John Maloney repo owner

    In addition, our competition motherboard is developed based on ESP32, and it has 8MB of RAM. I wonder if we can expand the threshold to 3000 or above.

    To increase that limit, you would need to create a fork of MicroBlocks and modify both the MicroBlocks IDE and the firmware running on the board. Since MicroBlocks in China is being served by a mirror server, that is certainly possible.

    However, someone on your team would need to make those changes and maintain the fork. If you choose to do that, I'd be happy to advise. I wonder if Wen Jie could help with that?

  3. Log in to comment