Skip to content

strings: optimize ToLower() #60127

@IGLOU-EU

Description

@IGLOU-EU

Hi,
I want to optimize the ToLower function and its dependencies.
Reduce memory allocation, early return...

Why

I made a small pkg for patern matching https://github.com/IGLOU-EU/go-wildcard
I wanted to add a "case-insensitive" option, but it loses a lot of performance, even for an empty string.

Bench

BenchmarkMatch/0-16             454892713            0.9726 ns/op           0 B/op          0 allocs/op
BenchmarkMatch/1-16             349304181            2.928 ns/op           0 B/op          0 allocs/op
BenchmarkMatch/2-16             476728009            2.127 ns/op           0 B/op          0 allocs/op
BenchmarkMatch/3-16             290518609            3.822 ns/op           0 B/op          0 allocs/op
BenchmarkMatch/4-16             124291632            8.709 ns/op           0 B/op          0 allocs/op
BenchmarkMatch/5-16             23469135            48.56 ns/op        0 B/op          0 allocs/op

BenchmarkMatchCasefold/0-16      7673000           216.3 ns/op        48 B/op          1 allocs/op
BenchmarkMatchCasefold/1-16      7057550           223.6 ns/op        48 B/op          1 allocs/op
BenchmarkMatchCasefold/2-16      6580888           215.7 ns/op        48 B/op          1 allocs/op
BenchmarkMatchCasefold/3-16      3193930           451.2 ns/op        96 B/op          2 allocs/op
BenchmarkMatchCasefold/4-16      3213775           473.1 ns/op        96 B/op          2 allocs/op
BenchmarkMatchCasefold/5-16      2305406           481.4 ns/op        32 B/op          1 allocs/op

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions