From 5a874ae241af64368e65b667592918b3fdb17177 Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Thu, 11 Mar 2021 05:34:50 -0500 Subject: Speed up ANSI code processing (#2368) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit speeds up the parsing/processing of ANSI escape codes by roughly 7.5x. The speedup is mostly accomplished by replacing the regex with dedicated parsing logic (nextAnsiEscapeSequence()) and reducing the number of allocations in extractColor(). #### Benchmarks ``` name old time/op new time/op delta ExtractColor-16 4.89µs ± 5% 0.64µs ± 2% -86.87% (p=0.000 n=9+9) name old speed new speed delta ExtractColor-16 25.6MB/s ± 5% 194.6MB/s ± 2% +661.43% (p=0.000 n=9+9) name old alloc/op new alloc/op delta ExtractColor-16 1.37kB ± 0% 0.31kB ± 0% -77.31% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ExtractColor-16 48.0 ± 0% 4.0 ± 0% -91.67% (p=0.000 n=10+10) ``` --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f246508f..8b37ef9c 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,9 @@ test: $(SOURCES) github.com/junegunn/fzf/src/tui \ github.com/junegunn/fzf/src/util +bench: + cd src && SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" -run=Bench -bench=. -benchmem + install: bin/fzf build: @@ -153,4 +156,4 @@ update: $(GO) get -u $(GO) mod tidy -.PHONY: all build release test install clean docker docker-test update +.PHONY: all build release test bench install clean docker docker-test update -- cgit v1.2.3