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

Uwe Schindler commented on LUCENE-5640:
---------------------------------------

In addition, the code we now have is like LambdaMetaFactory in Java 8: The code 
used by the Token attribute factory or the PackedAttributeFactory is now:

{code:java}
public static final AttributeFactory DEFAULT_TOKEN_ATTRIBUTE_FACTORY =
  
AttributeFactory.getStaticImplementation(AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY,
 PackedTokenAttributeImpl.class);
{code}

whose abstract newInstance() method does the same like a closure with 
{{PackedTokenAttributeImpl::new}} in Java 8. The trick here is to get the 
constructor non-reflective and call it with dynamic linking. So this is really 
the correct way to do this.

This will improve also the speed with other addAttributes() where we don't have 
the combined factory, like in FuzzyQuery or whenever we add single attributes.

The small overhead in the example (I don't see it in Java 8) that Robert 
measured could be removed by replacing the above code snippet with:

{code:java}
public static final AttributeFactory DEFAULT_TOKEN_ATTRIBUTE_FACTORY =
  new 
AttributeFactory.StaticImplementationAttributeFactory<>(AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY,
 PackedTokenAttributeImpl.class) {
  @Override
  public PackedTokenAttributeImpl newInstance() { return new 
PackedTokenAttributeImpl(); }
};
{code}

But this makes code less readable, especially when we add new packed attribute 
impls (we could think of providing them for various other combinations). As 
said, the very small lambda overhead is neglectible, because we reuse.

It would also be interesting to compare the good old non-packed AttributeImpl 
with that approach! I think we have an improvement here, too, but packing is 
still better (we spare the reflective call, but we still have to populate the 
maps).

> Cleanup Token class
> -------------------
>
>                 Key: LUCENE-5640
>                 URL: https://issues.apache.org/jira/browse/LUCENE-5640
>             Project: Lucene - Core
>          Issue Type: Sub-task
>          Components: modules/analysis
>            Reporter: Uwe Schindler
>             Fix For: 4.9, 5.0
>
>         Attachments: LUCENE-5640.patch, LUCENE-5640.patch, LUCENE-5640.patch, 
> LUCENE-5640.patch
>
>
> We should remove code duplication in the Token class:
> - copy constructors
> - reinit() shit
> - non-default clone()
> This is too bugy. Most of the methods can be simply removed. In fact, Token 
> should just look like a clone of all AttributeImpl it implements.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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

Reply via email to