-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Clarify what specifying the module name does with & #13668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When the capture operator is given a module name, a remote/external capture | ||
is created. Remote captures are faster than local captures. For more | ||
information, refer to the ["Functions" section in the Erlang Reference Manual](https://www.erlang.org/doc/system/eff_guide_functions.html#function-calls). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a bit misleading, because imported functions would also be external, it isn't about the m.f/a
syntax:
iex> &to_timeout/1
&Kernel.to_timeout/1
Perhaps the point could be focused on &local_function/1
versus &__MODULE__.local_function/1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the correction! Will do
Note that local captures dispatch to the version of the module which created | ||
them, while remote captures dispatch to the current version of the module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since hot code reloading is not so common, I think it is worth making this explicit this is only applies in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK!
Thanks for your suggestion! Updated the wording, let me know any other changes I can make. I'm new to this so I'm not attached to any wording. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you! 💜
Just wondering (question for the team), would an admonition block (e.g. Local versus remote captures
) be clearer?
Co-authored-by: Jean Klingler <[email protected]>
Are we 100% sure that remote captures are faster than local captures? Could we have some benchmarks on latest versions to verify? I'd be actually quite surprised to see a difference knowing how they are implemented underneath. |
@michalmuskala yes I did a quick one for https://groups.google.com/g/elixir-lang-core/c/rW_BRCULsGk/m/GeMd5Mn4AgAJ, it showed a very small gap which should be irrelevant for most cases but does exist.
|
The benchmark linked compares the performance of both crating and using the capture. The text change in documentation talks about the performance of using them - I'm not convinced this benchmarks fully proves the conclusion presented here, specifically that, as you noticed, there is indeed an expected difference in efficiency of creating such function objects |
Thank you, this makes sense, let me give it another try 👍 |
I tried to update the benchmark, but I can't get any consistent results, every run gives different results. I think the difference is almost too small to be noticeable. Perhaps we should reconsider documenting this? (at least the performance aspect, the hot code reload aspect might still be interesting?) |
I agree that the code reloading aspect is an important distinction and would be useful to document |
I think maybe the discussion on whether we should warn on local captures should happen in https://github.com/beam-telemetry/telemetry, and we keep this improvement here? |
@jyc can you please update to only mention local vs remote and their implications in regards to code reloading? Thank you. |
Absolutely! I removed the "This has performance implications" sentence. Do you think it would make sense for me to open a PR removing the warning in beam-telemetry/telemetry? |
💚 💙 💜 💛 ❤️ |
Hello! Thanks for making Elixir.
I ran into this error message from
:telemetry
and couldn't understand why it was happening, even after doing some web searches & reading the Elixir docs:After I asked on the Elixir Forums, I was pointed to a mailing list thread (https://groups.google.com/g/elixir-lang-core/c/rW_BRCULsGk/m/9rrYEwwtAwAJ 1) where someone said:
This is a PR to add a note about that to the docs for &. I am still new to the language so I am of course happy to move the documentation elsewhere and/or change the wording!