1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-04 04:31:00 +00:00
go-mtree/pkg/govis
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
..
COPYING subtree merge: cyphar/govis 2017-02-16 03:08:51 +11:00
govis.go govis: modernise errors 2025-09-23 04:15:07 +10:00
govis_test.go govis: modernise errors 2025-09-23 04:15:07 +10:00
README.md govis: add SPDX license tag 2025-09-23 04:14:37 +10:00
unvis.go unvis: improve performance by reducing allocations 2025-09-23 04:40:23 +10:00
unvis_test.go unvis: improve performance by reducing allocations 2025-09-23 04:40:23 +10:00
vis.go vis: improve performance by reducing allocations 2025-09-23 04:40:25 +10:00
vis_test.go vis: improve performance by reducing allocations 2025-09-23 04:40:25 +10:00

govis

govis is a BSD-compatible vis(3) and unvis(3) encoding implementation that is unicode aware and written in Go. None of this code comes from the original BSD code, nor does it come from go-mtree's port of said code. Because 80s BSD code is not very nice to read.

License

govis is licensed under the Apache 2.0 license.

govis: unicode aware vis(3) encoding implementation
Copyright (C) 2017-2025 SUSE LLC.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.