You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Li Li <fa...@gmail.com> on 2010/11/03 09:08:06 UTC

question about inline function in java

hi all
    we found function call in java will cost much time. e.g replacing
Math.min with a<b?a:b will make it faster. Another example is lessThan
in PriorityQueue when use Collector to gather top K documents. Yes,
use function and subclass make it easy to maintain and extend. in
C/C++, we can use inline fuction to optimize. What about java? I see
many codes in lucene also inline many codes mannully.
   such as implmented hash map in processDocument,
SegmentTermDocs.read  "// manually inlined call to next() for speed".
   Is there any compiler option for inline in java? Or we may hardcode
something for time consuming tasks

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: question about inline function in java

Posted by Edward Drapkin <ed...@wolfram.com>.
On 11/3/2010 3:08 AM, Li Li wrote:
> hi all
>      we found function call in java will cost much time. e.g replacing
> Math.min with a<b?a:b will make it faster. Another example is lessThan
> in PriorityQueue when use Collector to gather top K documents. Yes,
> use function and subclass make it easy to maintain and extend. in
> C/C++, we can use inline fuction to optimize. What about java? I see
> many codes in lucene also inline many codes mannully.
>     such as implmented hash map in processDocument,
> SegmentTermDocs.read  "// manually inlined call to next() for speed".
>     Is there any compiler option for inline in java? Or we may hardcode
> something for time consuming tasks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>

The JVM does optimizations like this with its JIT compiler, which 
operates at runtime and optimizes "hot spots" in the execution of the 
application.  Some resources you might want to look at:

http://en.wikipedia.org/wiki/Just-in-time_compilation

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/perf2.html

http://java.sys-con.com/node/1118894

Thanks,
Eddie

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: question about inline function in java

Posted by Peter Karich <pe...@yahoo.de>.
  Hi,

do not ever optimize premature in java (and other jit languages like 
javascript etc)!

if you have a bottleneck -> optimize that. and only that. but take care 
how you compare statements.
be sure that you run some loops before. see the first comment of Aleksey 
Shipilev here:

http://karussell.wordpress.com/2009/05/21/microbenchmarking-java-compare-algorithms/

jit is very clever in optimizing code: so code as simple (and 'stupid') 
as possible to be understandle by jit ;-)
I.e. concentrate your time and effort on algorithms not on bytecode.

Regards,
Peter.

> hi all
>      we found function call in java will cost much time. e.g replacing
> Math.min with a<b?a:b will make it faster. Another example is lessThan
> in PriorityQueue when use Collector to gather top K documents. Yes,
> use function and subclass make it easy to maintain and extend. in
> C/C++, we can use inline fuction to optimize. What about java? I see
> many codes in lucene also inline many codes mannully.
>     such as implmented hash map in processDocument,
> SegmentTermDocs.read  "// manually inlined call to next() for speed".
>     Is there any compiler option for inline in java? Or we may hardcode
> something for time consuming tasks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org