Re: [go-nuts] Re: is it possible to speed up type assertion?

2018-11-26 Thread larytet
This logger https://github.com/ScottMansfield/nanolog is roughly 2x faster than ZAP and will work on all Go platforms. I want my logs to be collected and stored. I do not want to think where and when I can or can not log. 300ns and up (and not deterministic in my tests) blocking call is someth

Re: [go-nuts] Re: is it possible to speed up type assertion?

2018-11-26 Thread larytet
Talking about loggers and ZAP (interesting idea to accommodate API to the JSON) The following code gets 40ns/op type FieldType uint8 type Field struct { Key string Type FieldType Integer int64 Stringstring Interface interface{} } const ( // UnknownType i

Re: [go-nuts] Re: is it possible to speed up type assertion?

2018-11-26 Thread larytet
Do you mean this // This is straight from the https://github.com/uber-go/zap plabook func (b *Binlog) LogStructured(msg string, fields ...Field) error My first goal was to allow drop in replacement for the log package I have to handle 50K queries/s on a mediocre machine. My time budget is about

[go-nuts] Re: is it possible to speed up type assertion?

2018-11-26 Thread larytet
The ugly hack below shaves 20% from the switch-case type iface struct { tab *unsafe.Pointer data *unsafe.Pointer } func getInterfaceData(arg interface{}) unsafe.Pointer { return unsafe.Pointer*iface)(unsafe.Pointer(&arg))).data)) } // Cast the integer argument to uint64 and call

[go-nuts] Re: is it possible to speed up type assertion?

2018-11-25 Thread larytet
This code is ~20% slower (probably) func (b *Binlog) writeArgumentToOutput(writer writer, arg interface{}) error { var err error rv := reflect.ValueOf(arg) var v uint64 if k := rv.Kind(); k >= reflect.Int && k < reflect.Uint { v = uint64(rv.Int()) err = writer.write

[go-nuts] Re: is it possible to speed up type assertion?

2018-11-25 Thread larytet
This code fails my tests with "panic: interface conversion: interface {} is int32, not int" switch argKind { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect. Int64: i := uint64(arg.(int)) err = writer.write(b.ioWriter, unsafe.Pointer(&i)) case ref

[go-nuts] Re: is it possible to speed up type assertion?

2018-11-25 Thread larytet
These are great tips! Thank you! This is the context for the code above https://github.com/larytet/binlog/blob/master/binlog.go#L548 The following switch has exactly the same performance switch arg := arg.(type) { case int: i := uint64(arg) err = writer.write(b.ioWriter

[go-nuts] Re: is it possible to speed up type assertion?

2018-11-25 Thread larytet
The code below consumes ~40% of the total execution time. According to the profiler i := uint64(arg.(uint32)) is a major contributor // Cast the integer argument to uint64 and call a "writer" // The "writer" knows how many bytes to add to the binary stream // Type casts from interface{} to intege