From 26bce7119200f37f8b9f3ddc1a2c76c85f7c88be Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 21 Apr 2023 12:51:25 +0100 Subject: Changes the implementation of Atomise and Compound to no longer use goroutines This results in a massive performance boost, ~4x speedup --- subex/main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'subex/main.go') diff --git a/subex/main.go b/subex/main.go index 9824f10..bb688e9 100644 --- a/subex/main.go +++ b/subex/main.go @@ -103,13 +103,13 @@ func pruneStates(states []SubexBranch) (newStates []SubexBranch) { } // Run the subex transducer -func RunTransducer(transducer SubexState, input <-chan walk.Atom) (output []walk.Atom, err bool) { +func RunTransducer(transducer SubexState, input []walk.Atom) (output []walk.Atom, err bool) { states := []SubexBranch{{ state: transducer, outputStack: OutputStackNil{}.push(nil), store: make(Store), }} - for piece := range input { + for _, piece := range input { var newStates []SubexBranch for _, state := range states { newStates = append(newStates, state.eat(piece)...) @@ -149,7 +149,12 @@ func Main() { close(out) }(jsonStream, tokenStream) - atoms := walk.Atomise(tokenStream) + var tokens []walk.WalkValue + for token := range tokenStream { + tokens = append(tokens, token) + } + + atoms := walk.Atomise(tokens) output, err := RunTransducer(transducer, atoms) if err { @@ -157,7 +162,7 @@ func Main() { return } - valueOut, error := walk.MemoryCompound(output) + valueOut, error := walk.Compound(output) if error != nil { fmt.Println(error.Error()) return -- cgit v1.2.3