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

Improve float allocation #5133

Closed
vicuna opened this issue Aug 23, 2010 · 3 comments

Comments

@vicuna
Copy link

commented Aug 23, 2010

Original bug ID: 5133
Reporter: @Chris00
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2017-02-16T14:18:34Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.13.0+dev
Fixed in version: 4.03.0+dev / +beta1
Category: back end (clambda to assembly)
Child of: #5204
Monitored by: "Pascal Cuoq" @ygrek @glondu eaburns @hcarty gildor @Chris00 pzimmer @alainfrisch @mmottl

Bug description

There have been a number of significant improvements in float handling in 3.12 but the following example shows on could go further:

Program 1 ------------------------------
let r = ref 0.0 in
for i = 0 to 1000_000_000 do r := float i done;
Printf.printf "%f\n" !r;
Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words

1000000000.000000
words: 2000000363.000000
2.79user 0.00system 0:02.79elapsed 99%CPU (0avgtext+0avgdata 4208maxresident)k
0inputs+0outputs (0major+313minor)pagefaults 0swaps

Program 2 ------------------------------
let r = ref 0.0 in
for i = 0 to 1000_000_000 do r := float i done;
Printf.printf "%f\n" (!r +. 0.);
Printf.printf "words: %f\n" (Gc.stat ()).Gc.minor_words

1000000000.000000
words: 363.000000
1.20user 0.00system 0:01.20elapsed 99%CPU (0avgtext+0avgdata 3152maxresident)k
0inputs+0outputs (0major+247minor)pagefaults 0swaps

The second version allocates much less and is way faster on my machine (Linux poincare 2.6.35 #1 SMP Fri Aug 20 14:34:25 CEST 2010 x86_64 GNU/Linux). Both programs were compiled to native code. It would be nice not to have to resort to such tricks to improve performance! Couldn't the compiler figure out this optimization?

@vicuna

This comment has been minimized.

Copy link
Author

commented Apr 12, 2012

Comment author: @Chris00

See also bug #5204.

@vicuna

This comment has been minimized.

Copy link
Author

commented Apr 12, 2012

Comment author: @alainfrisch

Indeed, this is a typical case where the boxing/unboxing strategy proposed in #5204 works nicely and avoids having to force manually the unboxing by adding an ad hoc "+. 0.".

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 4, 2015

Comment author: @alainfrisch

Fixed by new unboxing strategy in 4.03.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.