Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastMath might actually be slowing down the system #6

Closed
nusco opened this issue May 18, 2015 · 1 comment
Closed

FastMath might actually be slowing down the system #6

nusco opened this issue May 18, 2015 · 1 comment

Comments

@nusco
Copy link
Owner

nusco commented May 18, 2015

Recently I found out that FastMath actually seems to be making the system slower on the whole – which means that this class might damaging all the four of them: performance, precision, simplicity and memory footprint. (It was supposed to get more of the first, at the price of the other three).

Try gradle testPerformance to run a 4000-ticks experiment and time it. @acisternino had warned me that optimizing Java's trigonometric operations, or even benchmarking them, was non-trivial.

Now I'm really confused. The naive test in FastMath's main() shows clearly superior performance over Java's Math, at least when it comes to arctangents. The non-naive micro-benchmarks from @acisternino also seem to confirm that FastMath is faster. And on top of that, I'm positive that my previous experiments with testPerformance clearly showed increased performance when using FastMath.

I'd like to get to the bottom of this. @acisternino, what do you think?

@nusco
Copy link
Owner Author

nusco commented May 18, 2015

@acisternino: I ran another simple benchmark, and there seems to be no doubt that FastMath is heavily slowing down the system as a whole, even as it seems to speed up individual calculations. See for yourself in branch without_fastmath. If you want to make it more obvjous, try pumping up PerformanceTest to 10 Kticks and see for yourself. This test is the closest to a real system running (minus graphics), so I'd consider it reliable – and in fact, just running the same experiment with/without FastMath and timing it seems to confirm that this class is slowing down the system.

By now I'm tempted to just delete FastMath for good, but I'll wait until you give me an opinion. I have no reasonable explaination for this.

[Update: Cipster, ignore this comment. I realized that I couldn't compare two runs with/without FastMath, even with the same seed, because the rounding errors, although minimal, resulted in a completely different evolutionary path. This is the butterfly effect in action: if you have a different number of creatures in the two experiments, then you cannot reliably compare the speeds.

So I made a temporary change to the code to disable all stuff that has an effect on the number of items: I removed death, reproduction, food spawning and food consumption. I ran two experiments with the same seed (1234) and I got 1 million ticks in 330 seconds with FastMath, and 348 seconds with java.Math. It's not a large difference, and we might question whether it's worth it – I still don't understand what kind of impact the rounding has on evolution, so maybe it's still a good idea to use standard java math. On the other hand, the benchmark is in favour of FastMath, so I'll close this issue for now.]

@nusco nusco closed this as completed May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant