Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Marshal to use strings.Builder #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lucastheisen
Copy link

@lucastheisen lucastheisen commented Feb 26, 2022

Similar to #6, but a smaller modification, added benchmarks, and should make it past the CI. The benchmarks show a pretty significant improvement:

Before:

      Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkMarshalNEntries$ github.com/go-ldap/ldif

      goos: linux
      goarch: amd64
      pkg: github.com/go-ldap/ldif
      cpu: Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
      BenchmarkMarshalNEntries/marshal_100-12      1000000000  0.001498 ns/op            0 B/op       0 allocs/op
      BenchmarkMarshalNEntries/marshal_1000-12     1000000000    0.1485 ns/op            0 B/op       0 allocs/op
      BenchmarkMarshalNEntries/marshal_10000-12  111295240700           ns/op  94516468448 B/op  349306 allocs/op
      PASS
      ok  github.com/go-ldap/ldif 13.154s

After:

      Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkMarshalNEntries$ github.com/go-ldap/ldif

      goos: linux
      goarch: amd64
      pkg: github.com/go-ldap/ldif
      cpu: Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
      BenchmarkMarshalNEntries/marshal_100-12     1000000000  0.0001769 ns/op  0 B/op  0 allocs/op
      BenchmarkMarshalNEntries/marshal_1000-12    1000000000  0.001784 ns/op   0 B/op  0 allocs/op
      BenchmarkMarshalNEntries/marshal_10000-12   1000000000  0.02262 ns/op    0 B/op  0 allocs/op
      BenchmarkMarshalNEntries/marshal_100000-12  1000000000  0.2143 ns/op     0 B/op  0 allocs/op
      PASS
      ok    github.com/go-ldap/ldif 3.329s

Without this (or similar patch), ldif marshaling is basically unusable for a reasonably sized directory.

Lucas Theisen added 2 commits February 26, 2022 16:21
Before:
  Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkMarshalNEntries$ github.com/go-ldap/ldif

  goos: linux
  goarch: amd64
  pkg: github.com/go-ldap/ldif
  cpu: Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
  BenchmarkMarshalNEntries/marshal_100-12      1000000000  0.001498 ns/op            0 B/op       0 allocs/op
  BenchmarkMarshalNEntries/marshal_1000-12     1000000000    0.1485 ns/op            0 B/op       0 allocs/op
  BenchmarkMarshalNEntries/marshal_10000-12  111295240700           ns/op  94516468448 B/op  349306 allocs/op
  PASS
  ok  github.com/go-ldap/ldif 13.154s
Looks like at least 2 orders of magnitude improvement at 1000 entries

After:
  Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -bench ^BenchmarkMarshalNEntries$ github.com/go-ldap/ldif

  goos: linux
  goarch: amd64
  pkg: github.com/go-ldap/ldif
  cpu: Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
  BenchmarkMarshalNEntries/marshal_100-12     1000000000  0.0001769 ns/op  0 B/op  0 allocs/op
  BenchmarkMarshalNEntries/marshal_1000-12    1000000000  0.001784 ns/op   0 B/op  0 allocs/op
  BenchmarkMarshalNEntries/marshal_10000-12   1000000000  0.02262 ns/op	   0 B/op  0 allocs/op
  BenchmarkMarshalNEntries/marshal_100000-12  1000000000  0.2143 ns/op	   0 B/op  0 allocs/op
  PASS
  ok  	github.com/go-ldap/ldif	3.329s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants