Difference between Supervisors and DynamicSupervisors what am I missing?

This is an important distinction that was not clear to me in the docs or guides, this makes things a lot clearer, thanks!

I’m aware that this strategy is deprecated from reading lots and lots of old posts about it :see_no_evil:. However, I was still confused that we could add children dynamically to Supervisor because of the wording on the guides.

I saw they were different by looking at the implementation, but have you found this documented somewhere? The documentation of child_spec/1 from DynamicSupervisor only points to the Supervisor docs.

What do you mean by “permanent” in this case? Besides the point on efficiency that @josevalim made, how would that work? I just want to get the wording right here, perhaps I’m not understanding what “permanent” and “dynamic” truly means in this scenario.

Hey @josevalim, I think what has been tripping me up in the docs and guides is that there’s some nuance in the language that doesn’t make the distinction immediately obvious. Improving on your suggestion, I think this would make it a little bit clear, what do you think?

Differently from the Supervisor module, which requires its children to be given when the supervisor starts, a DynamicSupervisor starts with no children. Instead, children are only started on demand via start_child/2 and there is no ordering between them. This allows the DynamicSupervisor to hold millions of children by using efficient data structures and to execute certain options, such as shutting down, concurrently.

By the way, is there some way we can improve the reference on the other side as well? When I read this section, that states: To dynamically supervise children, see DynamicSupervisor, it seems that this is the only way it can be done and not just the most efficient way as you mentioned (it’s my general perception while reading the guides as well).