- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Java server vm troubles with Scala code
Thu, 2009-02-19, 19:21
Hi all,
today I wanted to have a close look at the code Scala generates for certain
constructs, in particular pattern matching.
I stumbled about a problem I can't seem to solve. I attached a sample scala
program to demonstrate it. It basically is repeated pattern matching on a
list.
Running it with the client VM (java -client -Xmx64m -Xms64m ...) gives these
results:
1,000 runs
Parameter match. Time: 7 ms
Global value match. Time: 0 ms
10,000 runs
Parameter match. Time: 1 ms
Global value match. Time: 1 ms
100,000 runs
Parameter match. Time: 4 ms
Global value match. Time: 13 ms
1,000,000 runs
Parameter match. Time: 66 ms
Global value match. Time: 84 ms
10,000,000 runs
Parameter match. Time: 325 ms
Global value match. Time: 474 ms
100,000,000 runs
Parameter match. Time: 2940 ms
Global value match. Time: 4318 ms
However, running it with the server vm gives me headaches, Running with
java -server -Xmx64m -Xms64m):
1,000 runs
Parameter match. Time: 7 ms
Global value match. Time: 0 ms
10,000 runs
Parameter match. Time: 2 ms
Global value match. Time: 1 ms
100,000 runs
Parameter match. Time: 61 ms
Global value match. Time: 84 ms
1,000,000 runs
Parameter match. Time: 250 ms
Global value match. Time: 480 ms
10,000,000 runs
Parameter match. Time: 2405 ms
Global value match. Time: 65213 ms
100,000,000 runs
Parameter match. Time: 16046 ms
Global value match. Time: 1151866 ms
As you can see the results of the "global pattern matching" are great with the
client vm but are terrible with the server vm. I'm using the latest Java 6
update (update 12).
-I checked with a profiler and can't see anything suspicious.
-I checked, it's not the garbage collector.
-I used the while loop to make sure it's not related to the inner class
generated by a for construct.
-I decompiled the bytecode with Jad, can't see anything suspicious, either.
-I tested with the latest Java 7 eap build, doesn't fix it.
- I know this is a microbenchmark which might be giving invalid results. If it
is, please let me know why :)
Does this mean that the Java server vm has troubles to optimise scalac's
bytecode?
(I surely wouldn't like that :)
Does anyone of you see the reason for the bad performance if the server vm is
used?
(I know that this is slightly offtopic.)
Thanks a lot,
Joachim
Thu, 2009-02-19, 20:47
#2
Re: Java server vm troubles with Scala code
I updated the code such that it does not run in the construct... on a 64 bit JVM running in server mode, the results are:
dpp@horse:~/Desktop$ scala com.ansorgit.ListVMTest2
1,000 runs
Parameter match. Time: 3 ms
Global value match. Time: 0 ms
10,000 runs
Parameter match. Time: 1 ms
Global value match. Time: 1 ms
100,000 runs
Parameter match. Time: 6 ms
Global value match. Time: 4 ms
1,000,000 runs
Parameter match. Time: 0 ms
Global value match. Time: 1 ms
10,000,000 runs
Parameter match. Time: 5 ms
Global value match. Time: 5 ms
100,000,000 runs
Parameter match. Time: 57 ms
Global value match. Time: 56 ms
100,000,000,000 runs
Parameter match. Time: 56432 ms
Global value match. Time: 56330 ms
(Note that I added the Dr. Evil loop count of 100B)
Thanks,
David
On Thu, Feb 19, 2009 at 10:21 AM, Joachim Ansorg <nospam@joachim-ansorg.de> wrote:
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
dpp@horse:~/Desktop$ scala com.ansorgit.ListVMTest2
1,000 runs
Parameter match. Time: 3 ms
Global value match. Time: 0 ms
10,000 runs
Parameter match. Time: 1 ms
Global value match. Time: 1 ms
100,000 runs
Parameter match. Time: 6 ms
Global value match. Time: 4 ms
1,000,000 runs
Parameter match. Time: 0 ms
Global value match. Time: 1 ms
10,000,000 runs
Parameter match. Time: 5 ms
Global value match. Time: 5 ms
100,000,000 runs
Parameter match. Time: 57 ms
Global value match. Time: 56 ms
100,000,000,000 runs
Parameter match. Time: 56432 ms
Global value match. Time: 56330 ms
(Note that I added the Dr. Evil loop count of 100B)
Thanks,
David
On Thu, Feb 19, 2009 at 10:21 AM, Joachim Ansorg <nospam@joachim-ansorg.de> wrote:
Hi all,
today I wanted to have a close look at the code Scala generates for certain
constructs, in particular pattern matching.
I stumbled about a problem I can't seem to solve. I attached a sample scala
program to demonstrate it. It basically is repeated pattern matching on a
list.
Running it with the client VM (java -client -Xmx64m -Xms64m ...) gives these
results:
1,000 runs
Parameter match. Time: 7 ms
Global value match. Time: 0 ms
10,000 runs
Parameter match. Time: 1 ms
Global value match. Time: 1 ms
100,000 runs
Parameter match. Time: 4 ms
Global value match. Time: 13 ms
1,000,000 runs
Parameter match. Time: 66 ms
Global value match. Time: 84 ms
10,000,000 runs
Parameter match. Time: 325 ms
Global value match. Time: 474 ms
100,000,000 runs
Parameter match. Time: 2940 ms
Global value match. Time: 4318 ms
However, running it with the server vm gives me headaches, Running with
java -server -Xmx64m -Xms64m):
1,000 runs
Parameter match. Time: 7 ms
Global value match. Time: 0 ms
10,000 runs
Parameter match. Time: 2 ms
Global value match. Time: 1 ms
100,000 runs
Parameter match. Time: 61 ms
Global value match. Time: 84 ms
1,000,000 runs
Parameter match. Time: 250 ms
Global value match. Time: 480 ms
10,000,000 runs
Parameter match. Time: 2405 ms
Global value match. Time: 65213 ms
100,000,000 runs
Parameter match. Time: 16046 ms
Global value match. Time: 1151866 ms
As you can see the results of the "global pattern matching" are great with the
client vm but are terrible with the server vm. I'm using the latest Java 6
update (update 12).
-I checked with a profiler and can't see anything suspicious.
-I checked, it's not the garbage collector.
-I used the while loop to make sure it's not related to the inner class
generated by a for construct.
-I decompiled the bytecode with Jad, can't see anything suspicious, either.
-I tested with the latest Java 7 eap build, doesn't fix it.
- I know this is a microbenchmark which might be giving invalid results. If it
is, please let me know why :)
Does this mean that the Java server vm has troubles to optimise scalac's
bytecode?
(I surely wouldn't like that :)
Does anyone of you see the reason for the bad performance if the server vm is
used?
(I know that this is slightly offtopic.)
Thanks a lot,
Joachim
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Thu, 2009-02-19, 20:57
#3
Re: Java server vm troubles with Scala code
Paul, David,
thanks a lot for your valuable help. I should've thought of that.
My 32bit server vm here optimised the code away so that 100B iterations are
done in 0ms. That's what I expected :)
Thanks,
Joachim
> I updated the code such that it does not run in the construct... on a 64
> bit JVM running in server mode, the results are:
> dpp@horse:~/Desktop$ scala com.ansorgit.ListVMTest2
> 1,000 runs
> Parameter match. Time: 3 ms
> Global value match. Time: 0 ms
> 10,000 runs
> Parameter match. Time: 1 ms
> Global value match. Time: 1 ms
> 100,000 runs
> Parameter match. Time: 6 ms
> Global value match. Time: 4 ms
> 1,000,000 runs
> Parameter match. Time: 0 ms
> Global value match. Time: 1 ms
> 10,000,000 runs
> Parameter match. Time: 5 ms
> Global value match. Time: 5 ms
> 100,000,000 runs
> Parameter match. Time: 57 ms
> Global value match. Time: 56 ms
> 100,000,000,000 runs
> Parameter match. Time: 56432 ms
> Global value match. Time: 56330 ms
You shouldn't be using the Application trait for profiling. It means your entire benchmark runs inside a
constructor (and it should probably be deprecated if its pointy traps cannot be smoothed over.) I suspect that's
doing a job on your numbers.