[erlang-questions] Small performance hint: avoid abusing module_info(attributes)

Сергей Прохоров <>
Thu Sep 28 11:19:29 CEST 2017


It looks like attribute list is stored in `term_to_binary` format inside of
a .beam file.

So, each time you call `M:module_info(attributes)`, it decodes whole
attribute list using `binary_to_term`:

https://github.com/erlang/otp/blob/ddaed7774eb0a3bbaf6ee40153d2b082181a1223/erts/emulator/beam/beam_load.c#L6143

That may be ok for small list, but you, probably, have a lot of them (how
many?).

Another question is how did you lookup this attribute list? lists:keyfind?
This one, obviously, may be slow on a large lists.

But, at least, it doesn't look like `module_info(attributes)` uses any
locks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170928/03ba0fa9/attachment.html>


More information about the erlang-questions mailing list