Re: [go-nuts] Re: try to avoid additional memory allocations

2017-11-10 Thread krolaw
You could avoid allocations altogether by reusing the same byte array and passing it to the function. To retain readability, use a buffer and fmt.Fprintf On Saturday, 11 November 2017 04:00:48 UTC+13, Vasiliy Tolstov wrote: > > Thanks, i know that optimization can lead obscurity, but for

Re: [go-nuts] Re: try to avoid additional memory allocations

2017-11-10 Thread Vasiliy Tolstov
Thanks, i know that optimization can lead obscurity, but for critical paths i think that it useful =) 2017-11-10 8:41 GMT+03:00 peterGo : > Vasiliy, > > For portability, when you initialize cfg.WorkDir, clean it: cfg.WorkDir = > filepath.Clean(cfg.WorkDir) > > You can

Re: [go-nuts] Re: try to avoid additional memory allocations

2017-11-10 Thread Vasiliy Tolstov
Thanks! 2017-11-10 3:52 GMT+03:00 krolaw : > func oid2filepath(cfg *Config, oID uint64) string { >return fmt.Sprintf("%s%c%x%c%016x", cfg.WorkDir, filepath.Seperator, > oid2vid(oID), filepath.Seperator, oID) > } > > On Friday, 10 November 2017 09:58:03 UTC+13, Vasiliy

[go-nuts] Re: try to avoid additional memory allocations

2017-11-09 Thread peterGo
Vasiliy, For portability, when you initialize cfg.WorkDir, clean it: cfg.WorkDir = filepath.Clean(cfg.WorkDir) You can reduce the allocations from 5 to 1. However, optimization can lead to obscurity. For example, $ go test oid_test.go -bench=. BenchmarkVasiliy-4 200700 ns/op88

[go-nuts] Re: try to avoid additional memory allocations

2017-11-09 Thread krolaw
On Friday, 10 November 2017 13:52:51 UTC+13, krolaw wrote: > > func oid2filepath(cfg *Config, oID uint64) string { >return fmt.Sprintf("%s%c%x%c%016x", cfg.WorkDir, filepath.Separator, > oid2vid(oID), filepath.Separator, oID) > } > > On Friday, 10 November 2017 09:58:03 UTC+13, Vasiliy

[go-nuts] Re: try to avoid additional memory allocations

2017-11-09 Thread krolaw
func oid2filepath(cfg *Config, oID uint64) string { return fmt.Sprintf("%s%c%x%c%016x", cfg.WorkDir, filepath.Seperator, oid2vid(oID), filepath.Seperator, oID) } On Friday, 10 November 2017 09:58:03 UTC+13, Vasiliy Tolstov wrote: > > Hi. I have server that read/write data to many files (each