nokogiri
nokogiri copied to clipboard
optimization: consider alternative document free mechanisms that will allow setting `RUBY_TYPED_FREE_IMMEDIATELY`
trafficstars
See 08043802 for more context, but essentially:
- we parent unparented nodes at the last minute so that
xmlFreeDocfrees all the underlying memory for us - if two text nodes happen to end up siblings during that process, they are merged and libxml2 may allocate additional memory via ruby_xmalloc
- it may be unsafe to allocate memory during GC, warnings will be raised
Working on #2807 made me realize that we're doing more work during the deallocate function than I thought -- so it's both slower and less safe than it could be.
I have at least one idea, which is instead of parenting the unparented nodes, just call xmlFreeNode on them to avoid the parenting overhead.
just call
xmlFreeNodeon them to avoid the parenting overhead.
I tried that and got some crashes because the pointers weren't allocated, not too shure what kind of shenanigans libxml does internally, but I suspect it might have some kind of arenas.