-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/xgbin: remove use of most of the calls to binary.Read #15
Conversation
This CL gets rid of most of the calls to binary.Read which makes heavy use of reflection. Also, drop bufio.Reader in favor of io.Reader. Fixes dmitryikh#13.
Pull Request Test Coverage Report for Build 52
💛 - Coveralls |
@sbinet , thanks for your help to the project. I did some benchmark on loading speed: func BenchmarkHiggsLoading(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := XGEnsembleFromFile(filepath.Join("testdata", "xghiggs.model"))
if err != nil {
b.Skip(err.Error())
}
}
} [leaves] go test -bench Loading
goos: darwin
goarch: amd64
pkg: github.com/dmitryikh/leaves
BenchmarkHiggsLoading-8 5 207094885 ns/op <--- after removing binary.Read
PASS
ok github.com/dmitryikh/leaves 2.179s
[leaves] git rebase -i HEAD~2
Stopped at b724c93... [+] xgboost model loading benchmark
...
[leaves] go test -bench Loading
goos: darwin
goarch: amd64
pkg: github.com/dmitryikh/leaves
BenchmarkHiggsLoading-8 5 213136769 ns/op <--- before removing binary.Read
PASS
ok github.com/dmitryikh/leaves 2.177s As you can see the speedup is around ~4% If you wish you can repeat the experiment taking xghiggs.model from: Your PR seems nice to me. And if you don't want to add something, I will merge it. |
that's a bit disappointing... :) there's probably some more perf to squeeze out of |
@sbinet, I did some investigations:
[leaves] go tool pprof leaves.test cpu.out
File: leaves.test
Type: cpu
Time: Sep 21, 2018 at 7:21am (MSK)
Duration: 1.41s, Total samples = 1.28s (90.88%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) list ReadStruct
Total: 1.28s
ROUTINE ======================== github.com/dmitryikh/leaves/internal/xgbin.ReadStruct in /Users/d.khominich/code/go/src/github.com/dmitryikh/leaves/internal/xgbin/xgbin_io.go
0 1.13s (flat, cum) 88.28% of Total
. . 134: NameGbm string
. . 135:}
. . 136:
. . 137:// ReadStruct - read arbitrary data structure from binary stream
. . 138:func ReadStruct(reader *bufio.Reader, dst interface{}) error {
. 1.13s 139: err := binary.Read(reader, binary.LittleEndian, dst)
. . 140: if err != nil {
. . 141: return err
. . 142: }
. . 143: return nil
. . 144:} And memory allocations: (pprof) list ReadStruct
Total: 943.14MB
ROUTINE ======================== github.com/dmitryikh/leaves/internal/xgbin.ReadStruct in /Users/d.khominich/code/go/src/github.com/dmitryikh/leaves/internal/xgbin/xgbin_io.go
0 445.01MB (flat, cum) 47.18% of Total
. . 134: NameGbm string
. . 135:}
. . 136:
. . 137:// ReadStruct - read arbitrary data structure from binary stream
. . 138:func ReadStruct(reader *bufio.Reader, dst interface{}) error {
. 445.01MB 139: err := binary.Read(reader, binary.LittleEndian, dst)
. . 140: if err != nil {
. . 141: return err
. . 142: }
. . 143: return nil
. . 144:} Do you have any ideas how to speedup |
I am in the process of introducing a 'Decoder' type (like for json) that should deal with these pesky structs. |
out of date |
This CL gets rid of most of the calls to binary.Read which makes heavy
use of reflection.
Also, drop bufio.Reader in favor of io.Reader.
Fixes #13.