[ 
https://issues.apache.org/jira/browse/SOLR-912?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12657692#action_12657692
 ] 

Yonik Seeley commented on SOLR-912:
-----------------------------------

While we're going down the micro-benchmarking path, I tried eliminating 
ArrayList and got an additional 15-25% gain on common operations (create new, 
add between 5 and 15 elements, and then iterate over those elements later).  
This was with Java 1.6.  -Xbatch improved the results even more... ~40% - but 
this is just a micro-benchmark.

{code}
class NamedList2<T> implements INamedList<T> {

  protected NamedListEntry<T>[] nvPairs;
  protected int size;

  public NamedList2() {
    nvPairs = new NamedListEntry[10];
    size = 0;
  }

  @Override
  public int size() {
    return size;
  }

  @Override
  public String getName(int idx) {
    if (idx >= size) throw new ArrayIndexOutOfBoundsException();
    return nvPairs[idx].key;
  }

  @Override
  public T getVal(int idx) {
    if (idx >= size) throw new ArrayIndexOutOfBoundsException();    
    return nvPairs[idx].value;
  }

  private void resize() {
    NamedListEntry<T>[] arr = new NamedListEntry[nvPairs.length << 1];
    System.arraycopy(nvPairs, 0, arr, 0, size);
    nvPairs = arr;
  }

  @Override
  public void add(String name, T val) {
    if (size >= nvPairs.length) {
      resize();
    }
    nvPairs[size++] = new NamedListEntry<T>(name, val);
  }

[...]
{code}

> org.apache.solr.common.util.NamedList - Typesafe efficient variant - 
> ModernNamedList introduced - implementing the same API as NamedList
> ----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: SOLR-912
>                 URL: https://issues.apache.org/jira/browse/SOLR-912
>             Project: Solr
>          Issue Type: Improvement
>          Components: Analysis
>    Affects Versions: 1.4
>         Environment: Tomcat 6, JRE 6, Solr 1.3+ nightlies 
>            Reporter: Kay Kay
>            Priority: Minor
>             Fix For: 1.3.1
>
>         Attachments: NLProfile.java, SOLR-912.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> The implementation of NamedList - while being fast - is not necessarily 
> type-safe. I have implemented an additional implementation of the same - 
> ModernNamedList (a type-safe variation providing the same interface as 
> NamedList) - while preserving the semantics in terms of ordering of elements 
> and allowing null elements for key and values (keys are always Strings , 
> while values correspond to generics ). 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to