Increase concurrency, reduce allocs.
authorTom Clegg <tom@tomclegg.ca>
Sun, 29 Nov 2020 17:53:04 +0000 (12:53 -0500)
committerTom Clegg <tom@tomclegg.ca>
Sun, 29 Nov 2020 17:53:04 +0000 (12:53 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

tilelib.go

index 47241b858dd9e1e4c32c24146790827aee55fb3d..522159dede5994d42264d46b1b4f1bebdfdc9de2 100644 (file)
@@ -264,7 +264,7 @@ func (tilelib *tileLibrary) TileFasta(filelabel string, rdr io.Reader, matchChro
                label string
                fasta []byte
        }
-       todo := make(chan jobT)
+       todo := make(chan jobT, 1)
        scanner := bufio.NewScanner(rdr)
        go func() {
                defer close(todo)
@@ -273,8 +273,8 @@ func (tilelib *tileLibrary) TileFasta(filelabel string, rdr io.Reader, matchChro
                for scanner.Scan() {
                        buf := scanner.Bytes()
                        if len(buf) > 0 && buf[0] == '>' {
-                               todo <- jobT{seqlabel, fasta}
-                               seqlabel, fasta = strings.SplitN(string(buf[1:]), " ", 2)[0], nil
+                               todo <- jobT{seqlabel, append([]byte(nil), fasta...)}
+                               seqlabel, fasta = strings.SplitN(string(buf[1:]), " ", 2)[0], fasta[:0]
                                log.Debugf("%s %s reading fasta", filelabel, seqlabel)
                        } else {
                                fasta = append(fasta, bytes.ToLower(buf)...)
@@ -292,7 +292,7 @@ func (tilelib *tileLibrary) TileFasta(filelabel string, rdr io.Reader, matchChro
        totalFoundTags := 0
        totalPathLen := 0
        skippedSequences := 0
-       stats := make([]importStats, 0, len(todo))
+       var stats []importStats
        for job := range todo {
                if len(job.fasta) == 0 {
                        continue