1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-04 04:31:00 +00:00
Commit graph

11 commits

Author SHA1 Message Date
Aleksa Sarai
47086b0654
vis: improve performance by reducing allocations
By avoiding lots of small string allocations and reallocations when
appending to the output buffer, we can get a pretty decent performance
improvement (~6x for strings that do not require escaping, and ~2x for
most other multi-byte utf8 strings).

    goos: linux
    goarch: amd64
    pkg: github.com/vbatts/go-mtree/pkg/govis
    cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics
                    │    before    │                after                │
                    │    sec/op    │   sec/op     vs base                │
    Vis/NoChange-16   2372.5n ± 2%   379.1n ± 1%  -84.02% (p=0.000 n=10)
    Vis/Binary-16      2.104µ ± 8%   1.319µ ± 8%  -37.35% (p=0.000 n=10)
    Vis/ASCII-16      2070.0n ± 1%   737.3n ± 0%  -64.38% (p=0.000 n=10)
    Vis/German-16      3.380µ ± 1%   1.181µ ± 2%  -65.04% (p=0.000 n=10)
    Vis/Russian-16    10.927µ ± 2%   5.293µ ± 2%  -51.56% (p=0.000 n=10)
    Vis/Japanese-16    7.489µ ± 1%   3.990µ ± 0%  -46.72% (p=0.000 n=10)
    geomean            3.767µ        1.447µ       -61.58%

In theory we could get more performance if switch away from fmt.Sprintf,
but the %.N handling would be a little annoying to implement and so we
can punt on that for now.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:40:25 +10:00
Aleksa Sarai
70d3b19776
unvis: improve performance by reducing allocations
By using a buffer, we can avoid a bunch of small allocations that the
previous implementation did. Based on a few small benchmarks, the
performance improvement is very stark (~3x faster for strings that don't
require any escaping, and ~20% faster for multi-byte utf8 strings):

  goos: linux
  goarch: amd64
  pkg: github.com/vbatts/go-mtree/pkg/govis
  cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics
                    │    before    │                after                │
                    │    sec/op    │   sec/op     vs base                │
  Unvis/NoChange-16   1501.0n ± 0%   497.7n ± 1%  -66.84% (p=0.000 n=10)
  Unvis/Binary-16     1317.5n ± 3%   934.9n ± 9%  -29.04% (p=0.000 n=10)
  Unvis/ASCII-16      1325.5n ± 1%   616.8n ± 1%  -53.47% (p=0.000 n=10)
  Unvis/German-16     1884.5n ± 1%   986.9n ± 2%  -47.63% (p=0.000 n=10)
  Unvis/Russian-16     4.636µ ± 1%   3.796µ ± 1%  -18.11% (p=0.000 n=10)
  Unvis/Japanese-16    3.453µ ± 1%   2.867µ ± 1%  -16.99% (p=0.000 n=10)
  geomean              2.072µ        1.206µ       -41.77%

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:40:23 +10:00
Aleksa Sarai
01d93a93e2
unvis: make Next return chars and add Step helper
This makes it a little easier to read the common case code which
consumes the token and helps highlight which sub-parsers are explicitly
not consuming tokens until we are sure we are using it.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:40:21 +10:00
Aleksa Sarai
9bd1dffd9b
unvis: switch to methods for parser
Passing the parsers as an argument is very C-like and is not really as
idiomadic as just using methods (in my defence, I was still pretty green
when I wrote this code and I was trying to port some logic from C).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:40:18 +10:00
Aleksa Sarai
bcdb71fb56
unvis: add some more error tests
These error cases were already handled correctly, but we really should
have tests for them anyway. Now that we have proper error variables
declared we can also test for specific errors as well.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:40:15 +10:00
Aleksa Sarai
fbada2e081
govis: modernise errors
This code was written before %w was added to Go, and there were a fair
few mistakes in the copy-pasted error code.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:15:07 +10:00
Aleksa Sarai
3ce83fca15
govis: add SPDX license tag
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:14:37 +10:00
Aleksa Sarai
d02f298ad4
govis: switch to testify tests
testify makes most bog-standard test checks much easier to read and
maintain, and is quite widely used. It wasn't really well known back
when govis was first written, but the migration is fairly
straight-forward for most tests.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-23 04:13:42 +10:00
04230dccdc
govis: comment for lint
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-06-30 15:06:50 -04:00
Aleksa Sarai
4ad871ca46
pkg: govis: remove travis-ci files
Since govis is now a subpackage, drop references to the project as a
govis package.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2017-02-16 05:18:02 +11:00
Aleksa Sarai
91d7ec8c89
subtree merge: cyphar/govis
govis is a reimplementation of vis(3) and unvis(3) specifically made to
be unicode aware. It was specifically rewritten to replace cvis and the
other go vis reimplementation we have in go-mtree.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2017-02-16 03:08:51 +11:00