The description of this PR 
<https://github.com/beam-telemetry/telemetry/pull/43> and this comment 
<https://github.com/beam-telemetry/telemetry/pull/43#issuecomment-840179783> 
suggest that the issue shows up when multiple processes concurrently call 
the function

... the issue is the copying of the anonymous function from ETS to the 
process heap (caller) requires a reference counter to be incremented for 
garbage collection. With the global capture, the function isn't copied and 
therefore doesn't need to be garbage collected when invoked



On Sunday, March 24, 2024 at 6:13:14 PM UTC-7 sabi...@gmail.com wrote:

> This is an interesting topic.
>
> I tried to benchmark these and sometimes local functions indeed show up as 
> slightly slower, but it is typically in the 0~2% range even for this 
> contrived example doing basically nothing. So I'm not sure if it is worth 
> highlighting the difference:
>
> https://github.com/sabiwara/elixir_benches/commit/9b721f3b19f8af9d9d63a30618cdafeaa6367883
>
> Checking the S file shows that external functions are just literals while 
> local functions are calling make_fun3:
>
> https://github.com/sabiwara/elixir_benches/commit/9b721f3b19f8af9d9d63a30618cdafeaa6367883#diff-3a3b83d8acad1d3b6faed87ba471843f4424b22c26c179bf1d86a87a880e8223R74-R93
>
> Even though, as far as I know, recent versions of Erlang 
> have optimizations to make sure the overhead of lambdas like this one 
> remains very small: https://github.com/erlang/otp/pull/6963.
>
>
> Le dim. 24 mars 2024 à 01:50, 'Rudolf Manusadzhian' via elixir-lang-core <
> elixir-l...@googlegroups.com> a écrit :
>
>> Hi there! Might be a naive question.
>>
>> Why don't we treat all local captures as external? Like at compile time, 
>> if it's possible, we could treat *&fun/0* as *&__MODULE__.fun/0* and get 
>> a free performance boost, if in the end they behave same.
>>
>> I was going thought the docs for :telemetry.attach/4 
>> <https://hexdocs.pm/telemetry/1.2.1/telemetry.html#attach/4> and the 
>> suggestion to avoid using *local* captures raise that thought.
>>
>> If that's not possible, does it make sense to add a note in the docs 
>> Kernel.SpecialForms.&/1 
>> # Capture 
>> <https://hexdocs.pm/elixir/1.16.2/Kernel.SpecialForms.html#&/1-capture> 
>> about 
>> the performance implications of local capture vs external or a 
>> recommendation?
>>
>> Thanks.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/c7065947-b48d-43e6-a450-387f6d4f1846n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/c7065947-b48d-43e6-a450-387f6d4f1846n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/c281b2c7-b25e-489c-bdd4-50fbecc71f59n%40googlegroups.com.

Reply via email to