mkodekar / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

FluentIterables toString can be overly expensive when displayed in a debugger #1802

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We use Iterables.filter, transform, etc, to walk over data that's sourced from 
external services, and is made available using objects of type 
AbstractIterator, which go back to the server to get more and more pages of 
data.

In a debugger (IntelliJ for example), the toString method is called, which is 
implemented in FluentIterable as Iterables.toString.

Obviously this is not desirable in the case that there is lots of data and/or 
we don't expect to consume all the data in one shot.

Unfortunately, we cannot just override the toString on these impacted instances 
because of the way Iterables.transform and FluentIterable.transform construct 
and return instances.

My ask is to change the implementation of toString so that it doesn't consume 
the whole iterator (perhaps an upper limit on elements?  perhaps something like 
.cycle() which just adds "(cycled)" to the toString?).

One implementation might be to just remember the order of the FluentIterable 
attached functions and describe the instance as opposed to describing the 
contents.  For instance, toString could return something like 'Based on 
Iterable "I" with transformer "T -> Z" and filter function "F"' where "I", "T 
-> Z" and "F" are the results of the toString() calls on the delegate Iterable, 
the transformer, and function objects.

Original issue reported on code.google.com by joesl...@gmail.com on 14 Jul 2014 at 3:41

GoogleCodeExporter commented 9 years ago
Thanks... I think this is something we've intended to do but just haven't 
gotten to yet.

Original comment by cgdecker@google.com on 14 Jul 2014 at 4:52

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 14 Jul 2014 at 4:53

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:08

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07