performance - JS DOM elements’ content-string properties: memory management and computation in current engines -
in dom, node
, element
types have many dynamic properties, e.g., node.textcontent
, element.innerhtml
, return string representations of nodes’ contents.
the dom specifications state these methods “return” domstrings
, i.e., string
s. they, of course, not specify when , how these strings allocated , computed. text nodes, implementation can return plain-text string content directly. element
s must create new strings contain tags , contents of descendant elements.
as far can tell, implementation may allocate memory these strings , compute values @ 4 points:
- immediately, when
element
first created; - lazily, scheduled sometime after
element
’s creation; - lazily, on demand @ point when getting string property
element
; - or lazily, on demand whenever string first used (i.e., returned string uses special, externally indistinguishable implementation returned
element
’s string properties dynamically generates value when needed).
these methods determine when strings’ memory freed. first 2 techniques cache string in element
object—they create reference string element
, , string not deallocated until element
is. third , fourth techniques might need not create such reference element
; string’s memory may deallocated long before element
is, long other references freed. in addition, implementation might use two, three, or of these possibilities based on heuristic.
which techniques modern browser engines use? question has clear performance ramifications, both in computation time , memory allocation, sort of dom manipulation , text retrieval. far can tell these properties’ performance characteristics unknown or not documented.
Comments
Post a Comment