Live data from Hacker News

Go Optimization Guide

goperf.dev

171–173 of 173 posts

Re: Go Optimization Guide

#171

Why doesn’t the compiler pack structs for you if it’s as easy as shuffling around based on type?

Because the organization of your struct is exactly how the memory have to be organized and that might be important for you. The compiler doesn't know your intended usage so it can't rework the structure at its will.

For example, you might take the block of memory and data and send it to another system that will decode it. Or you can take the block of memory and store it in a file or in a hardware device where it means something in this specific order.

Re: Go Optimization Guide

#172
post #154

Earlier quoted context omitted.

"any" is not structural typing.

any isn't a special type. It is an alias for interface{}. The empty set is trivially satisfied by all types, but obviously can be narrowed as you see fit.

I know, but having a type that is a supertype of everything is still not structural typing. Structural typing naturally has such a type, yes, whereas with nominal type systems it has to be explicitly introduced - but that still happens often enough, e.g. object in Python or System.Object in C#.

OP's point was that `any` in Go is much akin to duck typing in Python because in both cases the type check happens at runtime at the moment you're about to use the object. Yes, in Go, technically there's a separate step of downcasting to some interface type before you invoke the members, and it's that downcasting which fails, but c'mon, this is a pedantic distinction without a meaningful difference in practical usage scenarios of `any` to work around language limitations. The relevant thing is that it has all the same downsides.

Re: Go Optimization Guide

#173
post #65

"Although the struct Data contains a [1024]int array, which is 4 KB (assuming int is 4 bytes on the architecture used)" Huh,what? I mean, who uses 32b architecture by default?

Most C/C++ compilers have 32b int on 64b arch. Maybe the confusion comes from that. Also it would be 4KiB not 4KB.

What?

Article is about the Go compiler. On 64 bit arch Go int is 64 bits.

Post reply on HN