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

ASF GitHub Bot commented on LOG4J2-2478:
----------------------------------------

GitHub user DiegoEliasCosta opened a pull request:

    https://github.com/apache/logging-log4j2/pull/219

    LOG4J2-2478 Return the computed variables on each benchmark to avoid DCE

    As mentioned in [JIRA](https://issues.apache.org/jira/browse/LOG4J2-2478), 
this patch simply returns the computation on every benchmark that uses the 
static _consume_ method. We do that to prevent dead-code elimination, which is 
only partially addressed in the current implementation.
    
    Another patch that could simplify the benchmark code, and get considerably 
faster throughputs, would be to simply rely on _Blackhole.consume_ methods to 
sink the computation. We then, would not need the _consume_ method we have in 
the class.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/DiegoEliasCosta/logging-log4j2 
jmh-antipatterns-ignoredreturn

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/logging-log4j2/pull/219.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #219
    
----
commit 59a41bb5dbe2f5edba9c4b7eb68f309ad7f637ce
Author: DiegoEliasCosta <diegoelias1@...>
Date:   2018-10-15T11:21:30Z

    LOG4J2-2478 Return the computed variables on each benchmark to avoid DCE

----


> JMH Benchmarks in not consuming all computed variables (risk of DCE)
> --------------------------------------------------------------------
>
>                 Key: LOG4J2-2478
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2478
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Tests
>         Environment: I am reporting the result of 5 full executions with 
> default parameters (iterations, forks, warmups, etc..)
> Tests run on a Computational server with CPU: E5-1660-3.3GHZ (6 cores + HT), 
> 64 GB RAM.
>            Reporter: Diego Elias Damasceno Costa
>            Priority: Minor
>         Attachments: logginglog4j2-jmhantipatterns-retu.csv
>
>
> We are conducting a scientific study to investigate bad 
> practices/anti-patterns on creating micro-benchmarks using JMH, and we found 
> an instance of harmfull non-consumed computation in 
> `AbstractStringLayoutStringEncodingBenchmark`.
> As a good practice, every computation performed in inside the benchmark 
> should be consumed (see [JMH 
> Documentation|[http://hg.openjdk.java.net/code-tools/jmh/file/66fb723292d4/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_08_DeadCode.java].]
>  
> This is partially done here with the self-made consume method, but on some 
> benchmarks (such as baseline, usAsciiGetBytes) the return is not consumed in 
> the benchmark, which opens the possibility of a Dead-Code Elimination to be 
> performed by JVM. 
> *There is a very simple solution:* just return the long primitive calculated 
> by _consume()_ at the end of each benchmark. This is done on other benchmarks 
> of the project as well.
> In our tests, benchmarks were lightly affected (see attachment), with 
> Throughputs 5-35% lower after our fix patch. 
>  



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

Reply via email to