i doubt it will cause a performance issue (i think unicode.IsDigit
will be inlined), but if it is, you could always do the
traditional '0' <= r && r <= '9'.
unicode.IsDigit won't be inlined with the current compilers
since it declares a new variable in it's body. There's lots
of potential improvements that can made to the inlining code
and I'm sure we'll start to see them once Go 1 is out.
Anthony
To be precise, unicode.IsDigit won't be inlined because it
calls unicode.Is which declares a new variable in it's body.
A bit too quick on the trigger,
Anthony
yes, i was wondering that.
actually, i'm a bit surprised that it won't inline functions
that make calls that cannot be inlined. i suppose the
reasoning is that it wouldn't save much because the
call may be made anyway (it could, of course, save quite
a bit in this particular situation).
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
– Donald E. Knuth
You can pass the -llll flag (yes, four 'l's) to the compiler
and it will try to inline non-leaf functions. Compiling the
unicode package like this will indeed cause IsDigit to be
inlined.
Anthony
i had tried this, but it didn't work for me. i'd expect to see a
"can inline" message below.
% cat tst.go
package main
import (
"unicode"
)
func main() {
for i := rune(0); i < 200; i++ {
if unicode.IsDigit(i) {
println(true)
}
}
}
% go tool 6g -lllll -m $%
%
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
– Donald E. KnuthI would suggest you do the following (in order):1. Use unicode.IsDigit in your code whenever you need to check if a character is a digit.2. If required, measure the performance of your code.3. If unicode.IsDigit turns out to be a performance bottleneck, try to do something about it.
s/ that cannot be inlined//
The goal is to preserve information on crashes.
I've spent too long cursing inliners that make
programs undebuggable.
Russ
is it possible that in the future we could have a one-to-many PC->line number
mapping and so remove this restriction?
or is that not the issue?
yes, it is possible. i am still hoping for jetpacks though.
jetpacks would be ideal, of course, but i'm easily satisfied.
> is it possible that in the future we could have a one-to-many PC->line number
> mapping and so remove this restriction?
For the record, DWARF version 4 has this feature. It has a way to
record inlining information for, in effect, each instruction. That
permits debuggers to show a complete backtrace at each instruction,
including inlined functions. You can see this in current versions of
gcc and gdb.
Ian