Skip to content

Conversation

@lucastheisen
Copy link
Contributor

@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.

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
@cpuschma
Copy link
Member

I'm sorry for the delay, @lucastheisen. Thank you very much for your improvements! ❤️

@cpuschma cpuschma merged commit 1f8b40b into go-ldap:master Aug 20, 2025
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