Skip to content

Releases: bbrks/wrap

v2.7.0 - MinimumRaggedness

03 Feb 00:26
c041ccd

Choose a tag to compare

Adds a MinimumRaggedness wrapper option, to opt for a ~30x slower algorithm, but one that produces much nicer looking results.

The default greedy algorithm fills each line as much as possible until the input is exhausted. The optimal algorithm distributes words more evenly, resulting in more balanced line lengths.

Example (limit 46)

Default (greedy)

----------------------------------------------
Typographical irregularities, like
unpredictable justification and
disproportionate hyphenation, can disrupt
reading rhythm. Overly ambitious algorithms
often miscalculate line breaks, producing
orphaned words or inconsistent margins.
Strategic layout engines evaluate multiple
options simultaneously, redistributing content
to harmonize alignment and minimize visual
dissonance.
----------------------------------------------

With MinimumRaggedness

----------------------------------------------
Typographical irregularities,
like unpredictable justification and
disproportionate hyphenation, can
disrupt reading rhythm. Overly ambitious
algorithms often miscalculate line breaks,
producing orphaned words or inconsistent
margins. Strategic layout engines
evaluate multiple options simultaneously,
redistributing content to harmonize
alignment and minimize visual dissonance.
----------------------------------------------

Full Changelog: v2.6.0...v2.7.0

v2.6.0

02 Feb 23:48
d05a293

Choose a tag to compare

Much like the recent bbrks/go-blurhash update, I've applied some overdue TLC to this library too.


v2.6.0 brings performance improvements and reduced memory usage and various bug fixes.

Performance Summary

Wrap limit Time/op Bytes/op Allocs/op
10 -85% -96% -98%
80 -65% -76% -86%
120 -60% -69% -80%

Bug Fixes

  • Fixed CutLongWords cutting in the middle of multibyte UTF-8 sequences
  • Fixed #16 - Hyphen-breaks no longer drop the hyphen from the word
  • Fixed misc whitespace issues - leading/trailing spaces around breakpoints are now trimmed properly

Benchmarks

benchstat v2.5.0...v2.6.0 (click to expand)
goos: linux
goarch: amd64
pkg: github.com/bbrks/wrap/v2
cpu: AMD Ryzen 7 7800X3D 8-Core Processor           
            β”‚ bench-2.5.0.txt β”‚           bench-2.6.0.txt           β”‚
            β”‚     sec/op      β”‚    sec/op     vs base               β”‚
Wrap0-16          98.14n Β± 3%   107.00n Β± 2%   +9.03% (p=0.002 n=6)
Wrap1-16         11.179Β΅ Β± 3%    2.082Β΅ Β± 2%  -81.38% (p=0.002 n=6)
Wrap2-16         11.407Β΅ Β± 1%    2.300Β΅ Β± 2%  -79.84% (p=0.002 n=6)
Wrap5-16         11.667Β΅ Β± 0%    2.546Β΅ Β± 1%  -78.18% (p=0.002 n=6)
Wrap10-16         8.552Β΅ Β± 1%    1.244Β΅ Β± 1%  -85.45% (p=0.002 n=6)
Wrap25-16        3189.5n Β± 1%    612.8n Β± 1%  -80.79% (p=0.002 n=6)
Wrap80-16        1058.5n Β± 1%    367.8n Β± 3%  -65.25% (p=0.002 n=6)
Wrap120-16        748.8n Β± 1%    299.2n Β± 1%  -60.04% (p=0.002 n=6)
Wrap500-16       295.70n Β± 1%    76.54n Β± 0%  -74.12% (p=0.002 n=6)
Wrap1000-16      297.20n Β± 1%    76.45n Β± 1%  -74.28% (p=0.002 n=6)
Wrap5000-16      297.50n Β± 1%    76.41n Β± 1%  -74.32% (p=0.002 n=6)
geomean           1.494Β΅         405.6n       -72.84%

            β”‚ bench-2.5.0.txt β”‚          bench-2.6.0.txt          β”‚
            β”‚      B/op       β”‚    B/op     vs base               β”‚
Wrap0-16           464.0 Β± 0%   896.0 Β± 0%  +93.10% (p=0.002 n=6)
Wrap1-16         14624.0 Β± 0%   896.0 Β± 0%  -93.87% (p=0.002 n=6)
Wrap2-16         14624.0 Β± 0%   640.0 Β± 0%  -95.62% (p=0.002 n=6)
Wrap5-16         14624.0 Β± 0%   512.0 Β± 0%  -96.50% (p=0.002 n=6)
Wrap10-16        12104.0 Β± 0%   480.0 Β± 0%  -96.03% (p=0.002 n=6)
Wrap25-16         4896.0 Β± 0%   448.0 Β± 0%  -90.85% (p=0.002 n=6)
Wrap80-16         1872.0 Β± 0%   448.0 Β± 0%  -76.07% (p=0.002 n=6)
Wrap120-16        1424.0 Β± 0%   448.0 Β± 0%  -68.54% (p=0.002 n=6)
Wrap500-16         464.0 Β± 0%   448.0 Β± 0%   -3.45% (p=0.002 n=6)
Wrap1000-16        464.0 Β± 0%   448.0 Β± 0%   -3.45% (p=0.002 n=6)
Wrap5000-16        464.0 Β± 0%   448.0 Β± 0%   -3.45% (p=0.002 n=6)
geomean          2.432Ki        534.7       -78.53%

            β”‚ bench-2.5.0.txt β”‚          bench-2.6.0.txt          β”‚
            β”‚    allocs/op    β”‚ allocs/op   vs base               β”‚
Wrap0-16           2.000 Β± 0%   1.000 Β± 0%  -50.00% (p=0.002 n=6)
Wrap1-16          64.000 Β± 0%   1.000 Β± 0%  -98.44% (p=0.002 n=6)
Wrap2-16          64.000 Β± 0%   1.000 Β± 0%  -98.44% (p=0.002 n=6)
Wrap5-16          64.000 Β± 0%   1.000 Β± 0%  -98.44% (p=0.002 n=6)
Wrap10-16         52.000 Β± 0%   1.000 Β± 0%  -98.08% (p=0.002 n=6)
Wrap25-16         20.000 Β± 0%   1.000 Β± 0%  -95.00% (p=0.002 n=6)
Wrap80-16          7.000 Β± 0%   1.000 Β± 0%  -85.71% (p=0.002 n=6)
Wrap120-16         5.000 Β± 0%   1.000 Β± 0%  -80.00% (p=0.002 n=6)
Wrap500-16         2.000 Β± 0%   1.000 Β± 0%  -50.00% (p=0.002 n=6)
Wrap1000-16        2.000 Β± 0%   1.000 Β± 0%  -50.00% (p=0.002 n=6)
Wrap5000-16        2.000 Β± 0%   1.000 Β± 0%  -50.00% (p=0.002 n=6)
geomean            10.39        1.000       -90.38%

Full Changelog: v2.5.0...v2.6.0

Add CutLongWords option to Wrapper

02 Jan 17:41
11ff934

Choose a tag to compare

v2.5.0

Add CutLongWords option to Wrapper (#13)

Add patch version to tag

02 Jan 16:35

Choose a tag to compare

v2.4.0

Update README badges

Go modules support

13 Nov 18:41

Choose a tag to compare

Since v2.3.0, support for Go modules was added, and test dependencies were removed.

Add StripTrailingNewline option to wrapper

15 Nov 00:44
e60be0e

Choose a tag to compare

Merge pull request #8 from cjkreklow/strip-trailing-newline

Add StripTrailingNewline option

Fix off-by-one error on line length limits

05 Apr 21:54

Choose a tag to compare

v2.2.2

Fix off-by-one error on line lenth limits... Doh! :)

Fix minor rune-count issue

19 Feb 18:16

Choose a tag to compare

Merge pull request #7 from bbrks/hotfix/utf8-rune-counts

Count runes rather than number of bytes in string

Add Wrap shorthand

19 Feb 16:18

Choose a tag to compare

Merge pull request #6 from bbrks/add-shorthand-wrap

Add shorthand wrap func

Customisable newlines, and prefix/suffix support.

19 Feb 15:58

Choose a tag to compare

  • Add customisable newlines to the Wrapper
  • Add prefix/suffix support to inputs and outputs