How to reduce sketch size?

Hello again! Who can tell me how much the size of the sketch written in the IDE and XOD is very different? I have a sketch written in XOD; it occupies 89% of the memory in ARDUINO NANO. Although I saw sketches written in the IDE are much more complex in functionality and they fit in NANO without problems. Or am I mistaken and the sketches written in the IDE and XOD are the same in memory size? If I think correctly, is it possible to somehow reduce the size of the sketch and how to do it?

Part of the issue is that programming in IDE codes for exactly what you need. Programming in XOD is very generic and requires additional memory to track state of objects, etc. It is like the difference between programming in assembly vs BASIC. Writing a program in BASIC will be a lot easier, but there will be over-head and inefficiencies involved.

The developers for XOD have done a good job at reducing the size of compiled programs. There is probably room for more improvement, but if you are looking for the most efficient, smallest code, XOD is probably not the best option…

That said, I’m sure there are some nodes in XOD that require a lot more overhead than others. Not sure how to find them besides cutting out parts of your program just to see how they affect final size. You may be able to find a particular node (or set of nodes) that can be replaced with alternatives & cut down the size of your code quite a bit. The other alternatives are to code in a more efficient language or get an Arduino with more memory. The latter might be the best option for quick prototyping, then you can work on reducing code size to use a smaller Arduino later.

1 Like

Maybe you are compiling with debug enabled, try to load without debug.

Thanks for the detailed answer! I really like XOD and I will continue to work with it! XOD developers did a really good job !!! And in my situation, the best choice is an arduino with more memory. But I will also try to review the code and nodes to find an alternative replacement.

No, debugging is off. In the process of creating the patch, I already realized that debugging takes up a large amount of memory.
Friends, thanks again for the answers and tips!

the nth-input node takes up too many resources, if it has more than one or more entries that increases the size.

If so, you can try cesars/utils/dataselect

1 Like

Unfortunately, my project does not have these nodes. I have three flip-n-times nodes that control a stepper motor with three different settings. I tried to replace them with the SELECT node, but this node does not fit. Does anyone have any thoughts on how I can replace the three flip-n-times nodes? An approximate diagram of my project on the screen.

I doubt it will help much with your memory issue, but since you only want a pulse signal, you can replace “add” and “pulse-on-change” with “any” and feed it from flip-n-times-OUT instead of from Nc.

I have my doubts that any flip-n-times replacement will use a whole lot less memory. You can do a simple test by removing one of the flip-n-times & see how much memory is reduced…if it is significant, it might be worth looking at alternatives; if it is minimal, there is no reason to waste time on it.

It will obviously break your program, but you could remove one of the stepper nodes & upload just to see how much memory it saves. Repeat deleting the other stepper node. If a single node uses a good chunk of memory, you at least know where to look to try to save memory now…

ANY does not work with incoming number. I had to change it a bit (change the input to the number and add the third input to the code) (By the way, if such a node-input-numbers, output-pulse, with a variadic input appeared in the main library, I think it would be useful not only to me). I managed to reduce the code by 1% :rofl: Yes, this is an insignificant result. But he is positive! One flip-n-time node takes up 6% of the memory. Accordingly, 3 of these nodes, 18%, is already quite a lot! How to replace them, I have not yet found such a node in existing libraries. Does anyone know such a node? Unfortunately, my knowledge of C ++ does not allow me to create such a node myself, and there is absolutely no time for studying C ++ :frowning_face:

(it would not be bad if such a node appeared, it creates N - pulses by N number at the input)Безымянный

Strange thing! Changed the ANY node by adding a third input to the code and deleting the variadic node. I downloaded the patch several times to the board and it worked! Then, adding the “SELECT” node, my “ANY NUMBER” node stopped working and an error appeared
Error
UNEXPECTED_ERROR {“message”: “Explosion failed: Error: NO_VARIADIC_MARKERS {” trace \ “: [” @ / any-number \ “]}”}
The error has no formatter, which is a bug. Report the issue to XOD developers.
For a while I felt like a cool coder :rofl: :rofl: :rofl:
Adding a variadic node does not change the situation. Error in the difference of inputs and outputs. It is necessary to rewrite the code in a coordinated manner. So my hopes fell :rofl:

Any works with pulse…that’s why I told you to use the OUT pin of flip-n-times instead of the Nc pin. When OUT changes to true, it will convert that to a pulse; change to false will be ignored.

There is a bug that has been reported for some time, but 100% has not been solved, which does not eliminate some components such as variadic or non-implemented-in-xod, it does not always happen, I don’t know why.

To verify it, save the project as a Multifile XOD Proyect, open the folder and verify that those files are not available, also open with an editor and look for a “variadic” mention in patch.xodp

try it

image

I closed the program and when I opened it and now everything works with numerical inputs again. Loads onto the board and works properly with the equipment. Code inside ANY NUMBER

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
bool p1 = isInputDirty<input_IN1>(ctx);
bool p2 = isInputDirty<input_IN2>(ctx);
bool p3 = isInputDirty<input_IN3>(ctx);
if (p1 || p2 || p3)
emitValue<output_OUT>(ctx, true);
}

Not sure if this will work further without errors. Also, when saving Multifile XOD, all nodes are accessible and there is no mention of the Variadic value.

Sorry Google translator sometimes misinterprets thoughts and I do not quite understand your advice. Now it’s all clear. Thanks! I will definitely try this option!

YES! It is working! But he again stole my saved 1% :rofl: But I learned a little more about this node and working with this node! Thanks!

When deleting a single node from the sketch, flip-n-times showed a decrease of 6%. However, when loading one of this node into the board, it takes as much as 11%. Replacing the three flip-n-times nodes was pretty straightforward. (See the picture) This is not suitable for precision devices where every step of the motor matters, but in my project this is an ideal option. The number of steps is determined by the time on the delay node and is selected empirically. This has achieved a good reduction in the size of the sketch. 73% not bad

You should be able to get rid of the pulse-on-change node and connect the square-wave-OUT pin to the stepper node. Might save a little more memory.

Right! At the time of debugging, I put this node and forgot to remove :rofl:

Deleted! In the size of the sketch, this did not appear, and 73% remained. But moral satisfaction has been achieved! :rofl:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.