Is there an equation for calculating how much allowed memory would be used by the server when generating an html page with x number of dom elements?

StackOverflow https://stackoverflow.com/questions/16391184

  •  14-04-2022
  •  | 
  •  

Question

I have an administrator page for my drupal site that allows the admin to assign users to markets. I use a jquery accordian widget to display all markets for each user when clicked. The page has grown over the years and I have 72 markets and 157 user. So when the html is generated, there are at least 72 x 157 = 11,304 dom elements written into the html before the page is sent to the client. I break the allowed memory limit by reaching 143.75m, so I have to raise it when I want to add a user. I understand that this is bad design, but I'm interested in ways of understanding the complexity of very large html pages in regards to the work the server has to perform. Is there a general mathematical correlation between number of DOM elements to be generated on a page and the amount of allowed memory the server requires?

Was it helpful?

Solution

Memory on the server side will be largely unrelated to the number of DOM elements produced, as you will probably just be echoing those as strings. Obviously, the number of DOM elements will have a correlation to the size of the HTML (in bytes), and this may end up contributing to the amount of memory used. (This part is pretty easy to measure: save the resulting HTML as a file, and ask your OS how much space it takes up on disk.)

The largest portion of memory usage, though, will probably be the actual data (arrays, objects, intermediate variables) used to generate that HTML. For instance, if you are retrieving data from a database, the more rows you are dealing with, the more memory that resultset will take up; as it is transformed between different representations, it will likely be in memory multiple times.

It's worth noting that PHP 5.4 includes some pretty major improvements to memory usage, so if you're running an earlier version, it might be worth looking at the possibility of upgrading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top