peiffer-innovations / json_dynamic_widget

MIT License
226 stars 68 forks source link

Is this plugin memory efficient? #319

Closed Kaizodo closed 2 months ago

Kaizodo commented 2 months ago

This plugin is a great way to load dynamic layout and thanks to the developers who have worked on this awesome plugin, i would like to know if this plugin memory efficiant like does it loads all those renderer widgets into memory when inflating json layouts or it only loads the required components ?

for example

if my json layout only has a card with a button then card and button logic is loaded into memory or all the widgets like scaffold, icons , sliders , form-inputs etc everything will be loaded ?

jpeiffer commented 2 months ago

Really, there's a few answers.

  1. On mobile devices, unused memory is still powered so if you aren't concerned about multi-tasking app kills there is zero benefit to using less.
  2. The plugin strives to use only the memory it needs. So only the JSON you need and the components you want rendered are loaded.
  3. The code bundle is loaded so if you use a small part, you still get all the code loaded. This is in the orders of dozens of kilobytes though and most devices have memory in gigabytes. It shouldn't be noticeable when using small payloads, and probably still isn't unless huge ones are used.
  4. 3 can be mitigated by using a custom builder with the registry but the effort is unlikely worth the savings.

The biggest concern that I'd argue is valid is the bundle size. Because everything this references is dynamic, the tree shaker cannot remove anything from the bundle. This can add several hundred kilobytes to your final binary that you add to the app store. If you are trying to save every possible byte, this package is not for you. But if <1mb is ok to add to be able to use the dynamic nature of this package, you should be good to go.

Kaizodo commented 2 months ago

Thank you for the reply, i got it now less then 1mb is no big deal.