-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two minor memory improvements to
Dict
.
(1) When we are constructing a new `Dict` instance and are in the `Mutability.IMMUTABLE` situation, store `contents` as a `ImmutableMap` not a `LinkedHashMap`. The former suffices and uses less memory. There was already a TODO for this from adonovan@. Unfortunately, this optimization is minor in practice because the common case is that a `Dict` is constructed without `Mutability.IMMUTABLE`, but then `Mutability#freeze` gets called later. Therefore I think the bigger optimization opportunity would be to make it so that call to `Mutability#freeze` would magically go in and replace the `LinkedHashMap` instance with a `ImmutableMap` instance (this is not currently mechanically possible; see the javadoc for `Mutability#freeze`). I added a TODO for this. (2) Use `Dict#EMPTY` appropriately in all the code paths that construct `Dict` instances to avoid having multiple physical objects all for the same logical concept of "immutable empty dict". PiperOrigin-RevId: 432973333
- Loading branch information
1 parent
3b57ffa
commit 24ec910
Showing
2 changed files
with
97 additions
and
31 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