Strange speed dependency

Martin Buchholz martinrb at google.com
Mon Feb 2 23:02:37 UTC 2009


Ulf, the new UTF_8 decoder in very recent jdks is much faster,
and the primary trick that was used to achieve that
was reducing the size of the bytecode in the hot methods
and moving cold code to separate methods.

Martin

On Mon, Feb 2, 2009 at 14:35, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> Hi all,
>
> I have experienced a strange speed dependency of HotSpot compiled code after
> little change in code, which is not part of the "hot" loop.
> Is there any explanation for this behavior?
>
> Code before little change:
>
> class UTF_8_new extends Unicode {
>
>       // ....
>
>       private static CoderResult malformed(ByteBuffer src, int sp,
>                                            CharBuffer dst, int dp, int nb) {
>           src.position(sp -= nb - src.arrayOffset());
>           CoderResult cr = malformedN(src, nb);
>           updatePositions(src, sp, dst, dp);
>           return cr;
>       }
>
>       // ....
>
>           while (sp < sl) {
>               // ....
>                   int b2 = sa[sp++];
>                   int b3 = sa[sp++];
>                   int b4 = sa[sp++];
>                   if (isMalformed4(b1, b2))
>                       return malformed(src, sp-2, dst, dp, 2);
>                   if (isNotContinuation(b3))
>                       return malformed(src, sp-1, dst, dp, 3);
>                   if (isNotContinuation(b4))
>                       return malformed(src, sp, dst, dp, 4);
>                   if (dp >= dl - 1)
>                       return overflow(src, sp-4, dst, dp);
>                   int uc = (b1 << 18) ^ (b2 << 12) ^ (b3 << 06) ^ b4 ^
> 0x00381f80;
>               // ....
>           }
>
> The above code has following output (note gain against UTF_8_70$Decoder):
> time for sun.nio.cs.UTF_8_60$Decoder: 2701 ms
> time for sun.nio.cs.UTF_8_70$Decoder: 1984 ms
> time for sun.nio.cs.UTF_8_new$Decoder: 1720 ms  // gain: 264 ms
> time for sun.nio.cs.UTF_8_last$Decoder: 2110 ms
>
>
> Following small code change made the "hot" part of the loop much slower:
>
> class UTF_8_new extends Unicode {
>
>       // ....
>
>       private static CoderResult malformed(ByteBuffer src, int sp,
>                                            CharBuffer dst, int dp, int nb) {
>           src.position(sp - src.arrayOffset());    // removed subtraction of
> nb
>           CoderResult cr = malformedN(src, nb);
>           updatePositions(src, sp, dst, dp);
>           return cr;
>       }
>
>       // ....
>
>           while (sp < sl) {
>               // ....
>                   int b2 = sa[sp++];
>                   int b3 = sa[sp++];
>                   int b4 = sa[sp++];
>                   if (isMalformed4(b1, b2))
>                       return malformed(src, sp-4, dst, dp, 2);
>                   if (isNotContinuation(b3))
>                       return malformed(src, sp-4, dst, dp, 3);
>                   if (isNotContinuation(b4))
>                       return malformed(src, sp-4, dst, dp, 4);
>                   if (dp >= dl - 1)
>                       return overflow(src, sp-4, dst, dp);
>                   int uc = (b1 << 18) ^ (b2 << 12) ^ (b3 << 06) ^ b4 ^
> 0x00381f80;
>               // ....
>           }
>
> time for sun.nio.cs.UTF_8_60$Decoder: 2731 ms
> time for sun.nio.cs.UTF_8_70$Decoder: 1981 ms
> time for sun.nio.cs.UTF_8_new$Decoder: 1872 ms  // gain: 109 ms
> time for sun.nio.cs.UTF_8_last$Decoder: 2094 ms
>
> For complete sources compare following revisions (... and run
> UTF_8Benchmark.java ):
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=613
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=614
>
>
> -Ulf
>
>
>
>



More information about the core-libs-dev mailing list