otp
otp copied to clipboard
`application:get_env/1` performance improvement
Is your feature request related to a problem? Please describe.
application:get_env/1
calls application_controller:get_pid_env/1
which in turn calls ets:match/2
on ac_tab
with no bound key:
- https://github.com/erlang/otp/blob/master/lib/kernel/src/application.erl#L890
- https://github.com/erlang/otp/blob/master/lib/kernel/src/application_controller.erl#L345
ac_tab
can be large enough as it stores all the env vars for all the apps. At the same time,application:get_env/1
may be considered as a high-performance/minimum overhead function and be called frequently, e.g. per each request/operation being processed. There is no mentioning in the documentation, that this function should be used with care and/or thatapplication:get_env/2,3
is preferable performance-wise (as it's just a single ets lookup).
Describe the solution you'd like There are seem to be fairly easy fixes to improve efficiency:
- store inverted Pid to App index in the same tab, e.g.:
{Pid, {application_master, AppName}}
and avoid usingets:match/2
at all - store
{{application_master, '$1'}, Pid}
records in a separate tab, so that the table size can be kept more or less small
Describe alternatives you've considered
- at least add a note to
Application
documentation, warning a user that functions with ommited AppName may have a worse performance.
Additional context
There are more functions in application_controller
module implemented in a similar manner: get_pid_key/2
, get_pid_all_key/1
get_pid_all_env/1
If you agree that this worth a fix and have a preferred solution (either from the proposed ones or something new), I'd be happy to send a PR for that.
Thanks in advance!
After the first release candidate, we generally focus on bug fixes and polishing of features already included or planned for the release. To ensure that Erlang/OTP 27 will be as good as it possibly can be, we need to minimize the time we spend on things not to be included in the release. Therefore, we will not investigate/consider this feature request until after OTP 27 has been released. If we have not came back to it before September, feel free to remind us.