question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImmutableTable.get results in copyOf with actual copy being invoked

See original GitHub issue

I faced a strange performance situation with ImmutableTable.

Here is a stacktrace of what’s happening (it’s a profiling trace from async-profiler): image

Basically, it seems that calling ImmutableTable.get() results in ImmutableMap.copyOf() being called, and even though there is a comment in rowMap() saying that copyOf is called only for casting (https://github.com/google/guava/blob/master/guava/src/com/google/common/collect/SparseImmutableTable.java#L97), in practice, there is an actual copy via toArray().

I believe this is not meant to happen, is it?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
cpovirkcommented, Aug 10, 2020

For what it’s worth, I’m confident that the code would behave that way if we were seeing that kind of interaction between multiple classloaders. What I’m not at all confident in is that such an interaction was happening for the original poster.

If you’re curious, it’s definitely possible to test such things, but it’s definitely a pain 😃 You can see some examples custom classloaders in our tests, such as in this test: https://github.com/google/guava/blob/081c486173032e6096c912e3c297c1d74eddcf93/guava-tests/test/com/google/common/util/concurrent/AbstractFutureInnocuousThreadTest.java#L48

1reaction
cpovirkcommented, Oct 5, 2020

This does seem very strange, and it pops into my head from time to time.

The only even remotely plausible theory I have is that the ImmutableTable is an instance of the type from one classloader and the ImmutableMap call is using the type from another.

[edit: Actually, I don’t think I buy this: The two references to ImmutableMap should refer to the same type, since they are both source references from `ImmutableTable. I think?]

Read more comments on GitHub >

github_iconTop Results From Across the Web

com.google.common.collect.ImmutableTable.copyOf java code ...
Returns an immutable copy of the provided table. The Table#cellSet() iteration order of the provided table determines the iteration ordering of all views...
Read more >
Is it better to return an ImmutableMap or a Map? - Stack Overflow
If a mutative operation is invoked it creates a copy of the underlying map and all further invocations will be delegated to this...
Read more >
ImmutableMap (Guava: Google Core Libraries for Java 16.0 API)
ImmutableMap is convenient for public static final maps ("constant maps") and also lets you easily make a "defensive copy" of a map provided...
Read more >
ImmutableMap (Guava: Google Core Libraries for Java 31.1 ...
Returns true if this map maps one or more keys to the specified value. static <K,​V> ImmutableMap<K,​V>, copyOf​(Iterable<?
Read more >
Java - Coding Rules
When the call to a function doesn't have any side effects, what is the point of ... You should have received a copy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found