From 5e72de4ba23d85a05e03ce7e026b45ae26add049 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 7 Sep 2017 10:40:21 -0300 Subject: [PATCH] Revert "execext: use sync.Pool to instantiate parser and runner" This reverts commit 451b965fb0e0c21981eda28994dab2a4fc8e56f0. --- execext/exec.go | 38 ++++++------------------ execext/exec_test.go | 69 -------------------------------------------- 2 files changed, 9 insertions(+), 98 deletions(-) delete mode 100644 execext/exec_test.go diff --git a/execext/exec.go b/execext/exec.go index b551d2ac..6d1304cc 100644 --- a/execext/exec.go +++ b/execext/exec.go @@ -5,26 +5,11 @@ import ( "errors" "io" "strings" - "sync" "mvdan.cc/sh/interp" "mvdan.cc/sh/syntax" ) -var ( - parserPool = sync.Pool{ - New: func() interface{} { - return syntax.NewParser() - }, - } - - runnerPool = sync.Pool{ - New: func() interface{} { - return &interp.Runner{} - }, - } -) - // RunCommandOptions is the options for the RunCommand func type RunCommandOptions struct { Context context.Context @@ -47,24 +32,19 @@ func RunCommand(opts *RunCommandOptions) error { return ErrNilOptions } - parser := parserPool.Get().(*syntax.Parser) - defer parserPool.Put(parser) - - p, err := parser.Parse(strings.NewReader(opts.Command), "") + p, err := syntax.NewParser().Parse(strings.NewReader(opts.Command), "") if err != nil { return err } - r := runnerPool.Get().(*interp.Runner) - defer runnerPool.Put(r) - - r.Context = opts.Context - r.Dir = opts.Dir - r.Env = opts.Env - r.Stdin = opts.Stdin - r.Stdout = opts.Stdout - r.Stderr = opts.Stderr - + r := interp.Runner{ + Context: opts.Context, + Dir: opts.Dir, + Env: opts.Env, + Stdin: opts.Stdin, + Stdout: opts.Stdout, + Stderr: opts.Stderr, + } if err = r.Reset(); err != nil { return err } diff --git a/execext/exec_test.go b/execext/exec_test.go deleted file mode 100644 index a02cdcb2..00000000 --- a/execext/exec_test.go +++ /dev/null @@ -1,69 +0,0 @@ -// execext_test.go -package execext - -import ( - "context" - "io/ioutil" - "strings" - "sync" - "testing" - - "mvdan.cc/sh/interp" - "mvdan.cc/sh/syntax" -) - -func BenchmarkNoPool(b *testing.B) { - for i := 0; i < b.N; i++ { - f, err := syntax.NewParser().Parse(strings.NewReader(`echo "Hello, World!"`), "") - if err != nil { - panic(err) - } - r := interp.Runner{ - Context: context.TODO(), - Stdout: ioutil.Discard, - Stderr: ioutil.Discard, - } - if err = r.Reset(); err != nil { - panic(err) - } - if err = r.Run(f); err != nil { - panic(err) - } - } -} - -func BenchmarkPool(b *testing.B) { - parserPool := sync.Pool{ - New: func() interface{} { - return syntax.NewParser() - }, - } - runnerPool := sync.Pool{ - New: func() interface{} { - return &interp.Runner{} - }, - } - - for i := 0; i < b.N; i++ { - parser := parserPool.Get().(*syntax.Parser) - defer parserPool.Put(parser) - - f, err := parser.Parse(strings.NewReader(`echo "Hello, World!"`), "") - if err != nil { - panic(err) - } - - r := runnerPool.Get().(*interp.Runner) - defer runnerPool.Put(r) - - r.Stdout = ioutil.Discard - r.Stderr = ioutil.Discard - - if err = r.Reset(); err != nil { - panic(err) - } - if err = r.Run(f); err != nil { - panic(err) - } - } -}