You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "BELUGA BEHR (JIRA)" <ji...@apache.org> on 2019/01/01 21:28:00 UTC

[jira] [Commented] (THRIFT-4712) Improve Performance of ShortStack

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

BELUGA BEHR commented on THRIFT-4712:
-------------------------------------

I propose changing the implementation to more closely align with the JDK's {{ArrayList}} implementation where the "top" variable points at location of next index in the array, not the the largest index in the array which contains a value. Also, changed to use JDK's {{Arrays}} class for array manipulation.

Using JMH, the following results were produced:
{code:java}
Benchmark                        Mode  Cnt         Score        Error  Units
BenchmarkStack.javaStack        thrpt   60     42991.530 ±    215.511  ops/s
BenchmarkStack.shortStack       thrpt   60     82473.152 ±    380.779  ops/s
BenchmarkStack.shortStack2      thrpt   60    121064.717 ±   1097.112  ops/s

BenchmarkStack.shortStackPerf   thrpt   60  84236136.257 ± 646025.582  ops/s
BenchmarkStack.shortStack2Perf  thrpt   60  84597500.143 ± 673658.214  ops/s
{code}
The first set of tests builds a list of 2048 random short values, pushes them all into the array, then pops them all. The implementation proposed here was quite a bit faster. The second set of tests is a cut & paste of the tests in the Thrift code base into the JMH framework. Eight values are pushed into the Stack and pops are interwoven into the list of pushes. This new implementation edges it out (well within the margin or error).

> Improve Performance of ShortStack
> ---------------------------------
>
>                 Key: THRIFT-4712
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4712
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Library
>    Affects Versions: 0.12.0
>            Reporter: BELUGA BEHR
>            Priority: Minor
>
> {code:java|title=ShortStack.java}
> /**
>  * ShortStack is a short-specific Stack implementation written for the express
>  * purpose of very fast operations on TCompactProtocol's field id stack. This
>  * implementation performs at least 10x faster than java.util.Stack.
>  */
> {code}
> If speed is really important here, the ShortStack can be improved event a bit more.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)