From: Janne H. <ja...@hy...> - 2004-12-19 13:45:30
|
On Sun, 19 Dec 2004, Bardur Arantsson wrote: > I'm no expert on OCaml optimization, but I believe there > is a considerable performance benefit in using unsafe_get > (bget), unsafe_set (bset), etc. because you can avoid > bounds checking and always get proper inlining. Whether > this level of optimization is really necessary for BitSet > I'll leave as an exercise for the reader. :) ... > I don't think the compiler is currently clever enough (or > maybe the language semantics are not strict enough?) to do > all the needed inlining, and the bounds checking would > still slow you down. I took the current BitSet module, modified bget and bset to just use String.[] normally and added the couple of necessary char_of_ints and int_of_chars. I then went on a compiled the BitSet module with ocamlopt -unsafe (to turn off bounds checking). The resulting assembly is pretty much the same as with the Obj.magic+unsafe_get trickery, except that ocamlopt seems to be unable to inline int_of_char calls (which was a surprise to me). > I think compiling without bounds checking for "release" > builds is unwise since it may obscure serious bugs which > haven't been caught by the test suite. It's basically rude > to anyone using the library to (possibly) obscure bugs > within the library this way. Yes. However, it seems that many parts of the library *are* already using unsafe_gets. But I guess people can go and compile with -unsafe themselves if they want the extra performance (if any). ciao, janne |