[ 
https://issues.apache.org/jira/browse/LUCENE-2953?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003852#comment-13003852
 ] 

Dawid Weiss commented on LUCENE-2953:
-------------------------------------

There seems to be no consensus on how to deal with generic arrays. Even the JDK 
has two different implementations -- one in ArrayDeque (uses T[]), the other in 
ArrayList (uses Object[]). Creating an array of a given component type is (can 
be?) more costly than keeping an array Object[] because it needs to be done via 
call to Array.newArray (haven't checked though). Theoretically having a 
concrete-type array should speed up iterators (because no additional casts are 
needed), but I don't think this is the case. 

In fact, I just wrote a simple Caliper benchmark that compares these 
(attached), my results show the runtime times is nearly identical (probably 
within stddev).:

{noformat}
 0% Scenario{vm=java, trial=0, benchmark=Generic, size=1000000} 8985430.93 ns; 
σ=257329.28 ns @ 10 trials
33% Scenario{vm=java, trial=0, benchmark=GenericSubclass, size=1000000} 
8989486.27 ns; σ=207151.20 ns @ 10 trials
67% Scenario{vm=java, trial=0, benchmark=Object, size=1000000} 8767324.34 ns; 
σ=218235.97 ns @ 10 trials

      benchmark   ms linear runtime
        Generic 8.99 =============================
GenericSubclass 8.99 ==============================
         Object 8.77 =============================

vm: java
trial: 0
size: 1000000
{noformat}

> PriorityQueue is inheriently broken if subclass attempts to use "heap" 
> w/generic T bound to anything other then "Object"
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-2953
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2953
>             Project: Lucene - Java
>          Issue Type: Bug
>            Reporter: Hoss Man
>         Attachments: LUCENE-2953.patch
>
>
> as discovered in SOLR-2410 the fact that the protected "heap" variable in 
> PriorityQueue is initialized using an Object[] makes it impossible for 
> subclasses of PriorityQueue to exist and access the "heap" array unless they 
> bind the generic to Object.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to