On 04.06.25 10:45, Will Godfrey wrote:
I've not done any deep dives there for a very long time, and see that two
heavily used functions, sendDirect (39) and sendNormal (119) have been moved
entirely into a header file. I don't understand why this was done. These are
quite substantial functions, and it surely massively increases the eventual
code size, yet they are not critical for execution time so why was this done?


Hi Will,

I did that in 2019; this was one of  earlier clean-up works I did for Yoshimi;
you hat asked me explicitly if I could take a look at the code of the CLI,
because at that time it was hard to understand and to maintain.

How to organise code is often a trade-off between conflicting goals

(1) readability, keeping complexity down for the human maintainer
(2) data flow / room for the optimiser to do its work
(3) compilation time
(4) code size

The order on this list is basically how I see their relative importance.

Just consider that we compile with -O2 or -O3, which basically asks
the compiler to bloat the code massively in order to be faster.

Or consider that the common standard lib uses an alignment of 128 byte
on the heap by default, and things, which could be saved as a single bit
are placed into a 64-byte slot, because it makes a huge speed difference.


Furthermore, please have a look at these functions:

They are *exclusively* used by CmdInterpreter.cpp
So there is not much leverage for increasing compile times.

On the other hand, were these functions placed into a separate
compilation unit instead of being inlined, then the compiler would
be *forced* to code a real jump with argument passing for each
usage (which makes it 10-50 times slower than an inline function).

And what matters here more: we would force the compiler to place
all the various parts of the command block as parameters on the
stack, just to pull them off from there on the other side. And
the optimiser would not be able to exploit context knowledge
and to leave out code for branches in the function that
can not be activated in a given situation.

Most of the "content" of the function comprises such special
branches, while the actual "meat" is the tail call to InterChange.
And only for that small part there will be code emitted every time.

-- Hermann



_______________________________________________
Yoshimi-devel mailing list
Yoshimi-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/yoshimi-devel

Reply via email to