Dave Mitchell: > There was a second issue with COW1: for high COW numbers, the chain would > be long, and to free all N SVs in the chain would require a full traversal > of the chain for every sv_clear() call - you have to follow the chain > right round to find who in the chain is pointing at you. So freeing N SVs > took O(N^2) time. > > If this is an issue, I intend to use a hybrid approach. If the COW count > is 2, then use the "extra" field in the 2 bodies to link the two SVs > together in a chain of length 2 a la COW1. (I'm not sure what to do yet > for a COW count of 1: make "extra" point to itself, or set to NULL? - this > is an implementation detail.) I think a COW count of <= 2 will be very > common. If it is vastly more common than COWs with a count of 3, then it is likely worth doing as you suggest. > If the COW count is 3+, then instead, an integer field is allocated from > an arena, which holds the ref count,and all the "extra" fields instead > point to that ref count field. . But using this approach for all COWs would keep the code simpler. Could you possibly rig perl to count how high the refcounts go for each scalar and get some stats? mktables is a good candidate. I know from my previous COW benchmarks that mktables does represent (at least some) real-world code, because it gave me the same benchmarking results as real real-world code. (Or do you think it is too much effort to be worthwhile?)Thread Previous | Thread Next