forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve max capacity enforcement in DictPropertyMap
Summary: Previously DictPropertyMap was enforcing its max capacity limitation by calculating the requested allocation size and comparing it against the maximum possible allocation size. Unfortunately that was susceptible to integer overflow. Secondly, since the maximum capacity was only indirectly expressed as memory size instead of directly as number of entries, it was impossible to use in resizing logic. After doubling the capacity, if it happened to be larger that the maximum, we would simply fail instead of capping it at the maximum, since we didn't actually know the maximum. For example, when adding properties sequentially, we would eventually try to double the capacity from 130,000 to 260,000 properties and fail (this is with GenGCNC and 4MB segment size). However theoretically we could have instead increased the capacity to 167,000 (which is the maximum that fits) and added 37,000 more properties. Address both these shortcomings by calculating the maximum capacity at compile time. Having a constant available to compare against makes all overflow checks and resizing logic simple and efficient. Calculating the maximum capacity at compile time is not trivial since it depends on several constants, some of which are only implicitly known by the compiler (like alignment) and is not a simple equation. So, we perform a binary search over the solution space (all sizes between 0 and 0xFFFFFFFF >> 1) in a recursive constexpr function. A new test was added. To avoid excessive runtime and mmeory with collectors other than GenGCNC, it doesn't do anything if the maximum capacity is over 500,000. Reviewed By: amnn Differential Revision: D14162545 fbshipit-source-id: 60e4049c9dab35cc9e37d3a9fcad849b0e13a96c
- Loading branch information
1 parent
2b94684
commit 7e2bcb3
Showing
5 changed files
with
205 additions
and
34 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
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
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