Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intern repository mapping entries #19269

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -34,6 +36,15 @@
@AutoValue
public abstract class RepositoryMapping {

// All repositories generated by a module extension have the same repository mapping
// entries. Without interning, if a module extension generates N repositories, each such
// repository would have its own copy with (more than) N entries, resulting in memory usage that
// is quadratic in N.
// Note: We intern the entries, not the RepositoryMapping itself, because the latter also includes
// the owner repo, which differs between extension repos.
private static final Interner<ImmutableMap<String, RepositoryName>> ENTRIES_INTERNER =
BlazeInterners.newWeakInterner();

// Always fallback to the requested name
public static final RepositoryMapping ALWAYS_FALLBACK = createAllowingFallback(ImmutableMap.of());

Expand All @@ -60,7 +71,8 @@ public static RepositoryMapping createAllowingFallback(Map<String, RepositoryNam

private static RepositoryMapping createInternal(
Map<String, RepositoryName> entries, RepositoryName ownerRepo) {
return new AutoValue_RepositoryMapping(ImmutableMap.copyOf(entries), ownerRepo);
return new AutoValue_RepositoryMapping(
ENTRIES_INTERNER.intern(ImmutableMap.copyOf(entries)), ownerRepo);
}

/**
Expand Down
Loading