Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  profiling rules!  (Read 2665 times)
0 Members and 1 Guest are viewing this topic.
Offline gideon

Senior Newbie

« Posted 2007-03-01 22:21:11 »

I'd like you to hear a small success story on profiling. I am currently working on phys2d, see this topic, because I need it for a small project of mine called towship. From the very start I did think about efficiency in a bigger picture, for example testing all edges of both polygons would be very expensive (n*m) so I first select collision candidates (still quite some room for improvement there). But I didn't care much about smaller efficiencies like avoiding square roots wherever possible and those kind of things.

I decided to use a profiler to find the pieces of code where optimizations were really needed although I thought I knew more or less which parts would be problematic. Well, I couldn't have been more wrong. The first bit of very expensive code was the line-line intersection code, which I implemented with 4 crossproducts (where I only calculated the Z axis!). Rewriting those 10 lines of code immediately doubled the frame rate (from 1 to 2 fps in the profiler  Tongue).

The next bit of code was even more unexpected. I used a HashSet of integer which also was quite expensive, apparently it has a lot of overhead. I tried several alternatives, first I found a specialized IntegerSet library which was much faster but has some licensing issues (I wanted to include the source code itself). So I moved on and tried the java BitSet (although I was worried about the memory overhead in that case) which was faster than the HashSet but a little slower than the IntegerSet. Finally I tried a very simple handcoded singly linked list. It worked like a charm and was the fastest solution thusfar!

So, in roughly two hours work and only about 200 lines of code rewritten/changed, I increased performance by 400%!  Shocked

Next time I won't hesitate a second to use a profiler and if any of you have doubts .. well .. just change your mind!

The towship's adventures
Offline Mr_Light

Senior Devvie

Medals: 1


« Reply #1 - Posted 2007-03-02 18:55:14 »

Reminds me of what Jeff said, that bottlenecks are almost never where you think they will be.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Linuxhippy

Senior Devvie

Medals: 1

Java games rock!

« Reply #2 - Posted 2007-03-03 11:03:55 »

Well but often profilers tell a lot of garbage. I just used Netbean's profiler the last year and what I've seen is that the user has to take the results with a grain of salt. At least on my PCs Netbeans seems to over-estimate the importance of small, often called methods.
It told me that most of the time was spent in encryption code which is .... simply not true because this thing can decode 40mb/s whereas my app has not more than ~1mb/s throughput because its limited by other factors. Just because this method was called millions of times does not mean its expensive ^^

Short: Netbeans seems to over-estimate the importance of often called, small, cheap methods. They aren't as expensive as it tells you Wink

lg Clemens
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #3 - Posted 2007-03-03 11:16:17 »

It injects code into every method, small methods suffer from this much more than large methods.

I really love the 'embedded' -Xprof profiler because it doesn't seem to have this flaw.

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

Junior Devvie

Java games rock!

« Reply #4 - Posted 2007-03-04 15:19:46 »

If you set your profiler to sampling instead of code instrumentation, you shouldn't have that problem.
Pages: [1]
  ignore  |  Print  

DesertCoockie (54 views)
2018-05-13 18:23:11

nelsongames (86 views)
2018-04-24 18:15:36

nelsongames (76 views)
2018-04-24 18:14:32

ivj94 (761 views)
2018-03-24 14:47:39

ivj94 (93 views)
2018-03-24 14:46:31

ivj94 (645 views)
2018-03-24 14:43:53

Solater (104 views)
2018-03-17 05:04:08

nelsongames (187 views)
2018-03-05 17:56:34

Gornova (428 views)
2018-03-02 22:15:33

buddyBro (1088 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!