[Fwd: Re: hg: jdk7/tl/jdk: 6642323: Speeding up Single Byte Decoders; ...]

Christian Thalinger Christian.Thalinger at Sun.COM
Sat Jan 17 12:09:58 PST 2009


On Sat, 2009-01-17 at 20:23 +0100, Ulf Zibis wrote:
> Hi Christian,
> 
> In JDK 6 it's in sun.nio.cs.SingleByteDecoder, method decode().
> In JDK 7 it's also in sun.nio.cs.SingleByte$Decoder, method decode().
> 
> Here you can see, how I've played around with different byte loading 
> techniques:
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/array_io_string/src/sun/nio/cs/SingleByteFastDecoder.java?rev=&view=markup
> 
> Most up-to-date are:
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/src/sun/nio/cs/SingleByteMapDecoder.java?rev=&view=markup
> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunc/src/sun/nio/cs/SingleByteDirtyMapDecoder.java?rev=&view=markup
> 
> To run my project's classes after checkout, you first have to run once 
> make\src\build\tools\charsetmapping\GenerateMappingData by using 
> configuration "GenerateMappingData" in NetBeans IDE.

I decided to write my own, very simple micro-benchmark.  In the
following benchmark I get a speedup of about 0.9%:

    void foo() {
        byte[] ba = new byte[255];
        char[] ca = new char[255];
        for (int i = 0; i < 10000000; i++) {
            bar(ba, ca);
        }
    }

    void bar(byte[] ba, char[] ca) {
        for (int i = 0; i < ba.length; i++) {
            ca[i] = decode(ba[i]);
        }
    }

    public char decode(byte a) {
        return (char) (a & 0xFF);
    }

That speedup is quite OK but I doubt you will get as much in your tests.
But still, there's some room left for other optimizations.  Maybe I can
look into them too.

-- Christian




More information about the hotspot-dev mailing list