You're right, of course. Thanks. So is it true that package level initializations (that are used) require no runtime, other than some loader time to set up?
Jon On Wednesday, October 27, 2021 at 3:54:08 PM UTC-7 Ian Lance Taylor wrote: > On Wed, Oct 27, 2021 at 3:34 PM jlfo...@berkeley.edu > <jlfo...@berkeley.edu> wrote: > > > > I'm asking because preinitializing an executable binary, where possible, > seems like an obvious optimization. > > I'm writing baby programs as I'm learning Go, but even they have a > significant (to me) number of initializations > > that don't need to take up any execution time. On the other hand, modern > computers are so fast maybe it's not > > even worth paying attention to such things. > > > > I'm not an expert but I don't think the example you showed says anything > about preinitialized data. For example, > > I built the following trivial program: > > > > package main > > > > var x = []int {1,2,3,4,5,6,7,8} > > var s string = "abcdefg" > > var p float64 = 3.1415 > > > > func main() { > > } > > > > and then ran nm on the executable. I didn't see any sign of any of the > constants in my program. But, > > maybe I don't know what to look for. Your example shows data, but not > initialized data. Please > > correct me. > > The constants won't be in that program because nothing refers to them, > so the compiler will discard them. > > Try a program where the constants are actually used. For example, > print them out. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e094348b-43f7-4dd6-b9f9-f29c2354bef4n%40googlegroups.com.