Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Reduce ImmutableList duplication #200

Merged
merged 1 commit into from
Oct 5, 2016
Merged

Reduce ImmutableList duplication #200

merged 1 commit into from
Oct 5, 2016

Conversation

alicederyn
Copy link
Collaborator

When Guava is available, list properties are now initially ImmutableList instances in builders, optimistically avoiding unnecessary array allocation and ImmutableList duplication. If an object is cloned and modified using Builder.from without changing the list property, no ArrayList will be allocated: a single ImmutableList instance will be used throughout.

Once an ArrayList has been allocated, it will be used until the builder is discarded. While it might potentially be a memory saving to replace it with an ImmutableList once build() is called, in case multiple instances are minted without further modification, it would be difficult to retain the "live view" contract of the builder's getter method, which is currently done by returning an unmodifiable wrapper around the ArrayList.

This PR is part of issue #169.

When Guava is available, list properties are now initially ImmutableList instances in builders, optimistically avoiding unnecessary array allocation and ImmutableList duplication. If an object is cloned and modified using `Builder.from` without changing the list property, no ArrayList will be allocated: a single ImmutableList instance will be used throughout.

Once an ArrayList has been allocated, it will be used until the builder is discarded. While it might potentially be a memory saving to replace it with an ImmutableList once `build()` is called, in case multiple instances are minted without further modification, it would be difficult to retain the "live view" contract of the builder's getter method, which is currently done by returning an unmodifiable wrapper around the ArrayList.
@alicederyn alicederyn merged commit 7607b6e into master Oct 5, 2016
@alicederyn alicederyn deleted the shared.lists branch October 5, 2016 12:00
@alicederyn
Copy link
Collaborator Author

Note: This has been reverted.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants