-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "max waste" thresholds to avoid problems with COW and delib…
…erately overallocated pvs COW does not play nicely with "preallocate" algorithms. More specifically code like sv_gets() wants to preallocate a large buffer into $_ for performance reasons. Prior to COW this was just fine. When someone assigned $_ to a less volatile variable only the used portion of the buffer was copied, and the extended buffer would be reused by sv_gets() and all was well. With COW however this process is foiled. The preallocated buffer get shared, and then when $_ is updated the buffer is dropped from $_, leaving the other SV holding ownership of the overallocated buffer, and causing sv_gets() to allocate a new buffer entirely. This process would then repeat consuming time and lots of memory. This patch introduces a "wastage" check to COW. When decided if we should COW a string we look at the ratio and difference of SvCUR(sv) and SvLEN(sv), which represent the "actual string length" and the "allocated string length". When the difference exceeds a hard threshold, or when the ration exceeds a designated factor then we do not COW. This means that strings with large overallocations are not COWed. Exactly how this works out in practice, where SvGROW() *always* overallocates, is an open question. See: https://rt.perl.org/Ticket/Display.html?id=121796 This patch also slightly tweaks SvGROW() not to do roundup on the first allocation of the pv. Odds are good that the initial request realy does want exactly what they expected. (SvGROW contrary to what the name suggests is used for bother *extended* the size of a pv, and initializing it the first time.)
- Loading branch information
Showing
2 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters