RFR: 8042778: Getting all visible methods in ReferenceTypeImpl is slow
Jeremy Manson
jeremymanson at google.com
Wed Jul 9 00:22:41 UTC 2014
Sorry about the delay. What I said in the last message is nonsense.
values() returns a collection that calls containsValue() on the HashMap to
determine whether the object is present. That's potentially O(n). By
using HashSet(values()), we call contains() on a HashSet instead, which is
O(1).
I measured this with a class with 6K methods, and saw a 40x speedup in
invocations of visibleMethods() from this change.
Jeremy
On Fri, May 9, 2014 at 9:32 AM, Jeremy Manson <jeremymanson at google.com>
wrote:
> Hi David,
>
> Hm. This was done several years ago in response to a user request, and he
> claimed it cleared up the problem, but you're right - contains() on the
> collection returned by map.values() should have been an O(1) operation,
> both then and now. So I'll check into it and get back on this next week.
>
> Jeremy
>
>
> On Thu, May 8, 2014 at 8:17 PM, David Holmes <david.holmes at oracle.com>
> wrote:
>
>> Hi Jeremy,
>>
>>
>> On 9/05/2014 4:56 AM, Jeremy Manson wrote:
>>
>>> I'm testing out my newly acquired OpenJDK authorship with something
>>> simple. If I did this wrong, I apologize.
>>>
>>> Basically, the debugger becomes very slow if there are a lot of methods
>>> in a class. This can happen (O(thousands)) if you are using a code
>>> generation tool.
>>>
>>> http://cr.openjdk.java.net/~jmanson/8042778/webrev.00/
>>>
>>
>> I find it counter-intuitive that this makes things faster:
>>
>> - list.retainAll(map.values());
>> + list.retainAll(new HashSet<Method>(map.values()));
>>
>> Can you explain why introducing the intermediate HashSet improves things?
>> A comment in the code would also be good.
>>
>> Thanks,
>> David
>>
>>
>>
>>
>> Reviews from reviewers and committing from committers would be
>>> appreciated. Thanks!
>>>
>>> Jeremy
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20140708/cabd994d/attachment.html>
More information about the serviceability-dev
mailing list