On Sat, 13 Mar 2021, 17:00 Jan Mercl, <0xj...@gmail.com> wrote: > On Sat, Mar 13, 2021 at 5:52 PM Kevin Chadwick <m8il1i...@gmail.com> > wrote: > > > Very little resources, unless the map is actually used and not for long. > If you really need to control gos memory use, you need to preallocate > arrays in a long standing manner anyway, not for maps though, as you can't > delete without realloc. > > How did you figure out "very little resources"? > > What if there's a hot loop called a billion times doing something and > returning a non zero map in the very last call? We're then talking > about probably measurable slowdowns and gigabytes of garbage the > collector has to deal with. Allocating "preemptively" might be > sometimes a good idea, but that's a decision better left to humans as > the compiler usually does not have enough info to make that decision > right. > > Ignoring for now other techniques that might get the cost of this > down. They exist. >
If you are doing something a billion times then whatever you are doing is more expensive than allocating a zero map. You can also avoid that return if really necessary, which I doubt. It is right for optimisation steps to increase, over run of the mill stuff. Nonsense around performance is the reason that c sucks. > -- 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/CANNfpqcW2yRLefLzc9h1Dqk7Hr5ASwmrfoLD-QxhxwA7nwEzXw%40mail.gmail.com.