Implement a cache of data section pointers for records when writing the tree.

I added a test for this  as well.

This is the missing deduplication code that caused the XS-generated trees to
be so much larger than the pure Perl ones. Even though the serializer dedupes
individuals keys & values, we still get a huge win by deduplicating top-level
records, since many networks may have the same top-level record.
Fix a small memory leak.

We need to decrement the ref count for every hash we create
A small optimization for tree iteration

Rather than creating a new SV to track every seen node, we can use the same
reference to the global PL_sv_undef variable. On large trees, this avoids
millions of memory allocations (and frees) during tree iteration.