-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid modifying source objects when merging cache results.
As #4081 demonstrates, if there are key collisions during result merging, it's possible for source objects that were previously merged by reference into the target object (finalResult.result) to be modified destructively by later merges, which in some cases can lead to cycles in the results returned by the cache. This version of the merge function uses a copy-on-first-write strategy to ensure we never modify target objects that might once have been source objects. The code could have been considerably simpler if I didn't try to track pastCopies, but performance and memory usage are very important for this code, which is why I went to the trouble of limiting the number of shallow copies made during a single merge.
- Loading branch information
Showing
1 changed file
with
56 additions
and
12 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