You are completely correct. Assembly language subroutines shorten code size by eliminating duplicated code, but increase execution time due to the overhead of calling them.
// inline code | | // ASM call |
k instr. | | @RIP$123 |
| | D=A |
| | @ASM$FN |
| | 0;JMP |
| | (RIP$123) |
|
| | // ASM subroutine |
| | (ASM$FN) |
| | @R15 |
| | M=D |
| | k instr. |
| | @R15 |
| | A=M |
| | 0;JMP |
If the VM code contains n instances for this instruction, then the total code size and execution
times for the instructions is
| Code size | Exec. time |
Inline | n k
| n k |
call | 4 n + k + 5
| n(k + 9) |
A bit of algebra will reveal that for 9 ≤ k ≤ 12 there must be a least 3 instances of the command to get size reduction.
Optimization is generally a trade off between code size and execution speed.
--Mark