Incrementing a pass-by-reference value in a called routine on a hot path: 3 methods

12 views
Skip to first unread message

Finnian Reilly

unread,
Aug 20, 2026, 3:50:09 AM (6 days ago) Aug 20
to Eiffel Users

Eric Bezault

unread,
Aug 20, 2026, 4:09:50 AM (6 days ago) Aug 20
to eiffel...@googlegroups.com
Hello,

Several remarks about these benchmarks:

- I don't understand why you used:

value.set_item (value.item + 10)

and not:

value.set_item (10)

You should compare what is comparable.

- I wonder to what extent inlining can have an impact.
So I would rather write:

when 1 then
c_put_integer_32 (10, integer_ptr)
when 2 then
integer_ptr.memory_copy (10, {PLATFORM}.Integer_32_bytes)
when 3 then
value.set_item (10)

- Other methods are possible:
- use MANAGED_POINTER, but we will still suffer from the need for
`Integer_32_bytes` and `memory_copy` internally.
- use SPECIAL [INTEGER] with just one item, where access to `item`
and `put` should be inlined by the compiler.

--
Eric Bezault <er...@gobosoft.com>
Eiffel expert - available for freelance work
https://www.gobosoft.com



On 20/08/2026 9:50, Finnian Reilly wrote:
>
> Incrementing a pass-by-reference value in a called routine on a hot
> path: 3 methods <https://www.eiffel.org/blog/
> Finnian%20Reilly/2026/08/incrementing-pass-reference-value-called-
> routine-hot-path-3-methods>
>
>
> Table of Contents
>
> # Introduction <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-
> methods#Introduction>
> # The three methods <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-
> methods#The_three_methods>
> # The harness <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-
> methods#The_harness>
> # Results <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-methods#Results>
> # Why the spread <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-
> methods#Why_the_spread>
> # Takeaway <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-
> methods#Takeaway>
> # Notes <https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/
> incrementing-pass-reference-value-called-routine-hot-path-3-methods#Notes>
>
> https://www.eiffel.org/blog/Finnian%20Reilly/2026/08/incrementing-pass-
> reference-value-called-routine-hot-path-3-methods
>
> --
> SmartDevelopersUseUnderScoresInTheirIdentifiersBecause_it_is_much_easier_to_read
> (Eiffel = Security by Contract + C Speed)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Eiffel Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to eiffel-users...@googlegroups.com <mailto:eiffel-
> users+un...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/eiffel-
> users/4f5303c3-ec64-4e77-a8b5-582e2fb4669a%40eiffel-loop.com <https://
> groups.google.com/d/msgid/eiffel-users/4f5303c3-ec64-4e77-
> a8b5-582e2fb4669a%40eiffel-loop.com?utm_medium=email&utm_source=footer>.

Eric Bezault

unread,
Aug 20, 2026, 5:02:30 AM (6 days ago) Aug 20
to eiffel...@googlegroups.com
> Tested on my old Eiffel Studio 16.05/gcc compiler setup in finalized
> executable. I have not yet had time to migrate my benchmarking tools
> for v25.02 on my new machine.

Note that the most recent version is 25.12, not 25.02.

--
Eric Bezault <er...@gobosoft.com>
Eiffel expert - available for freelance work
https://www.gobosoft.com


On 20/08/2026 9:50, Finnian Reilly wrote:
>
> Incrementing a pass-by-reference value in a called routine on a hot
> --
> SmartDevelopersUseUnderScoresInTheirIdentifiersBecause_it_is_much_easier_to_read
> (Eiffel = Security by Contract + C Speed)
>

Finnian Reilly

unread,
Aug 20, 2026, 5:08:24 AM (6 days ago) Aug 20
to eiffel...@googlegroups.com
Good catch Eric,
in my current Xpact work incrementing a counter was uppermost in my mind, and I went back to an old benchmark and simply forgot that I was only setting a value. That is the nice thing about publishing on eiffel.org. You have time to fix ones stupid mistake before too many people notice.

Amended benchmark

Passes completed in a 500 ms window, more is faster, method 1 as baseline, listed fastest first:

Method Mechanism Passes / 500 ms Relative
1 C inline compound-assignment (+=) 536 100% (baseline)
3 EL_INTEGER_32_REF.add (field access) 52 −90.3%
2 TYPED_POINTER read + copy-back (two memory_copy) 45 −91.6%

I am starting to come around to the idea of pair programming.
Hope I can repay the favor some day. :-)

cheers
Finnian
Reply all
Reply to author
Forward
0 new messages