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

Compact slices when adding many duplicate names #7

Merged
merged 1 commit into from
Aug 9, 2022
Merged

Conversation

bep
Copy link
Owner

@bep bep commented Aug 9, 2022

Also, simplifying the merge logic.

Handling this case:

info := l.WithLevel(logg.LevelInfo)
for i := 0; i < 99999999; i++ {
    info = info.WithField("name", "value")
}

Which is not the right way to use this API, but probably common enough a case to add a check for.

name                                                       old time/op    new time/op    delta
Logger_context_many_fields_duplicate_names_with_field-10      995µs ± 1%     859µs ± 0%  -13.62%  (p=0.029 n=4+4)
Logger_context_many_fields_duplicate_names_with_fields-10     509µs ± 2%     331µs ± 0%  -35.07%  (p=0.029 n=4+4)

name                                                       old alloc/op   new alloc/op   delta
Logger_context_many_fields_duplicate_names_with_field-10     2.67MB ± 0%    1.53MB ± 0%  -42.84%  (p=0.029 n=4+4)
Logger_context_many_fields_duplicate_names_with_fields-10    1.97MB ± 0%    0.73MB ± 0%  -62.76%  (p=0.029 n=4+4)

name                                                       old allocs/op  new allocs/op  delta
Logger_context_many_fields_duplicate_names_with_field-10      30.0k ± 0%     30.0k ± 0%   -0.04%  (p=0.029 n=4+4)
Logger_context_many_fields_duplicate_names_with_fields-10     10.0k ± 0%     10.0k ± 0%   -0.12%  (p=0.029 n=4+4)

Also, simplifying the merge logic.

Handling this case:

```go
info := l.WithLevel(logg.LevelInfo)
for i := 0; i < 99999999; i++ {
    info = info.WithField("name", "value")
}
```

Which is not the right way to use this API, but probably common enough a case to add a check for.

```bash
name                                                       old time/op    new time/op    delta
Logger_context_many_fields_duplicate_names_with_field-10      995µs ± 1%     859µs ± 0%  -13.62%  (p=0.029 n=4+4)
Logger_context_many_fields_duplicate_names_with_fields-10     509µs ± 2%     331µs ± 0%  -35.07%  (p=0.029 n=4+4)

name                                                       old alloc/op   new alloc/op   delta
Logger_context_many_fields_duplicate_names_with_field-10     2.67MB ± 0%    1.53MB ± 0%  -42.84%  (p=0.029 n=4+4)
Logger_context_many_fields_duplicate_names_with_fields-10    1.97MB ± 0%    0.73MB ± 0%  -62.76%  (p=0.029 n=4+4)

name                                                       old allocs/op  new allocs/op  delta
Logger_context_many_fields_duplicate_names_with_field-10      30.0k ± 0%     30.0k ± 0%   -0.04%  (p=0.029 n=4+4)
Logger_context_many_fields_duplicate_names_with_fields-10     10.0k ± 0%     10.0k ± 0%   -0.12%  (p=0.029 n=4+4)
```
@bep bep merged commit 6dfcb74 into master Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant