Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  A poor man's struct (err, MappedObject)  (Read 10958 times)
0 Members and 1 Guest are viewing this topic.
Offline HamsterofDeath

Junior Duke




Java games rock!


« Reply #30 - Posted 2006-03-22 13:05:47 »

that backed-by-float[]-floatbuffer is STILL faster than using Unsafe.

i removed the double increment. saved about 2ms (of 29). i'm at 27 now. and i'm just reading the same element 10 million times now, so there shouldn't be cache flushing, right?.
the 10mb size shouldn't matter at all. every test iterates over every element.

on my machine, your direct float buffer is slower (a few ms) than the backed one...
Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #31 - Posted 2006-03-22 14:03:46 »

Let's not turn this thread into a benchmark frenzy, please.

The generated machine-code depends greatly on the JIT and can't really be predicted.

Sometimes FloatBuffers perform like float-arrays, sometimes they perform 10 times worse... let me show you what I mean:

Testing all 4 types of access:
1  
2  
3  
4  
float[]:               183ms
unsafe:                127ms
floatbuffer (direct):  1131ms
floatbuffer (float[]): 1035ms



Testing 3 types of access (all minus floatbuffer (float[]) )
1  
2  
3  
4  
float[]:               194ms
unsafe:                128ms
floatbuffer (direct):  147ms <--------- 7.7x faster
floatbuffer (float[]): 0ms



So code in other methods doing other things, affects performance in appearantly unrelated code!



When invoking this anywhere:
FloatBuffer.allocate(elements);
the code using DirectFloatBuffer drops performance by factor 7-8 Shocked

Probably because the JIT notices FloatBuffer now has more than 1 active subclass, so it can't optimize the general FloatBuffer class as it would do when only having DirectFloatBuffers around.


1  
2  
3  
4  
5  
6  
7  
benchmark();
printResults(); // floatbuffer (direct):  115ms

FloatBuffer.allocate(elements);

benchmark();
printResults(); // floatbuffer (direct):  971ms



* Riven learned something new today

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Spasi
« Reply #32 - Posted 2006-03-22 17:10:52 »

Probably because the JIT notices FloatBuffer now has more than 1 active subclass, so it can't optimize the general FloatBuffer class as it would do when only having DirectFloatBuffers around.

This situation is supposed to be better in Mustang with bimorphic call inlining.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #33 - Posted 2006-03-22 17:19:30 »

Life is better after 6  Grin

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline tusaki

Junior Duke


Medals: 1


In a mad world only the mad are sane.


« Reply #34 - Posted 2006-03-22 18:06:11 »

Here are my results for both benchmarks. (including suggested improvements)

Benchy
1  
2  
3  
4  
5  
6  
7  
8  
9  
before FloatBuffer.allocate()
   float[]:               211ms
   unsafe:                218ms
   floatbuffer (direct):  304ms

after FloatBuffer.allocate()
   float[]:               249ms
   unsafe:                219ms
   floatbuffer (direct):  1150ms


UnsafeDemo:
1  
2  
3  
4  
5  
6  
7  
8  
Array time: 30.98215 ms
x array= 1.24908006E9
unsafe time 52.641886 ms
x unsafe= 1249216512
Floatbuffer time: 31.53641 ms
x array= 1.24949581E9
Directbytebuffer2float time: 101.041054 ms
x array= 1.14874189E9


Offline HamsterofDeath

Junior Duke




Java games rock!


« Reply #35 - Posted 2006-03-22 20:23:08 »

the reason for unsafedemo being slower is that i use a "naked" unsafe instance. benchy extracts it from a bytebuffer.
if i use a bytebuffer's Unsafe, unsafe.get/put & arrays are almost equally fast. Unsafe is a bit faster, but you could have trouble avoiding the "base + (index<<bytes_of_type)"-calculation when accessing the buffer. if you can avoid it, Unsafe is the way to go Smiley
Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #36 - Posted 2006-03-22 21:22:11 »

My implementation avoids it... Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline chaosdeathfish

Junior Duke


Projects: 1



« Reply #37 - Posted 2006-03-28 22:06:47 »

Does the JVM do bounds-check removal on Buffer types? I know i does on arrays..
Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #38 - Posted 2006-03-28 22:11:26 »

1  
2  
3  
4  
float[]:               194ms
unsafe:                128ms
floatbuffer (direct):  147ms <--------- 7.7x faster
floatbuffer (float[]): 0ms

As it is faster than float[], I'd be very surprised if it did not remove bound-checks.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #39 - Posted 2006-03-29 09:52:37 »

Only the server VM does bounds check hoisting, AFAIK.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #40 - Posted 2006-03-29 10:04:39 »

Indeed. I run all benchmarks against the server-vm for erm.. performance-reasons Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline HamsterofDeath

Junior Duke




Java games rock!


« Reply #41 - Posted 2006-03-29 10:36:00 »

Does the JVM do bounds-check removal on Buffer types? I know i does on arrays..

i'd say: no. a bytebuffer's get and put methods are always a bit slower than direct array accesses. (at least the last 10 times i looked at the results)
if i simply call a bytebuffer's private put/get-methods (jdk hack) which don't do bounds checks manually, i'm almost at array speed (50% slower). if i inline the calls and access the unsafe object directly, using (base+(offset<<2)) as the address to get an int, i'm really almost at array speed (up to 10% difference, sometimes faster, sometimes slower, which means it's pretty equal). using any precalucated value as an address speeds things up, and i'm at 200% array speed.
i assume this means:
a) java uses the same calculation to access random values in arrays
b) java doesn't do array bounds checks if the vm can be sure that no evil index will be used.
Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (50 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (36 views)
2014-10-15 16:18:58

TehJavaDev (66 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!