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

refactor(log): elide keyval translation to map #15158

Merged
merged 2 commits into from
Feb 24, 2023
Merged

Conversation

mark-rushakoff
Copy link
Member

@mark-rushakoff mark-rushakoff commented Feb 24, 2023

Description

The zerolog Fields method accepts a []any in the same format we use in the Logger interface's methods, so translating the slice to a map is unnecessary.

Include microbenchmark to prove this difference.

Before omitting getLogFields:

BenchmarkLoggers/zerolog/empty_key_vals-10         	11605411	        90.57 ns/op	      24 B/op	       1 allocs/op
BenchmarkLoggers/zerolog/single_string-10          	 6691237	       179.2 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_small_int-10       	 6597535	       182.6 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_largeish_int-10    	 6357801	       189.6 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_float-10           	 5022015	       240.0 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_byte_slice-10      	 6291516	       189.9 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_duration-10        	 5478682	       218.1 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/two_values-10             	 4692778	       254.7 ns/op	      88 B/op	       4 allocs/op
BenchmarkLoggers/zerolog/four_values-10            	 2798709	       416.5 ns/op	     152 B/op	       6 allocs/op
BenchmarkLoggers/zerolog/eight_values-10           	 1460266	       822.2 ns/op	     280 B/op	      10 allocs/op

After omitting getLogFields:

BenchmarkLoggers/zerolog/empty_key_vals-10         	21484472	        55.89 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_string-10          	15827601	        74.40 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_small_int-10       	15395997	        77.92 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_largeish_int-10    	14214717	        84.11 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_float-10           	 9016212	       133.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_byte_slice-10      	13968756	        85.88 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_duration-10        	10588659	       113.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/two_values-10             	12969648	        93.72 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/four_values-10            	 9006982	       136.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/eight_values-10           	 4979397	       239.5 ns/op	       0 B/op	       0 allocs/op

Author Checklist

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

The zerolog Fields method accepts a []any in the same format we use in
the Logger interface's methods, so translating the slice to a map is
unnecessary.

Include microbenchmark to prove this difference.

Before omitting getLogFields:

BenchmarkLoggers/zerolog/empty_key_vals-10         	11605411	        90.57 ns/op	      24 B/op	       1 allocs/op
BenchmarkLoggers/zerolog/single_string-10          	 6691237	       179.2 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_small_int-10       	 6597535	       182.6 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_largeish_int-10    	 6357801	       189.6 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_float-10           	 5022015	       240.0 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_byte_slice-10      	 6291516	       189.9 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/single_duration-10        	 5478682	       218.1 ns/op	      56 B/op	       3 allocs/op
BenchmarkLoggers/zerolog/two_values-10             	 4692778	       254.7 ns/op	      88 B/op	       4 allocs/op
BenchmarkLoggers/zerolog/four_values-10            	 2798709	       416.5 ns/op	     152 B/op	       6 allocs/op
BenchmarkLoggers/zerolog/eight_values-10           	 1460266	       822.2 ns/op	     280 B/op	      10 allocs/op

After omitting getLogFields:

BenchmarkLoggers/zerolog/empty_key_vals-10         	21484472	        55.89 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_string-10          	15827601	        74.40 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_small_int-10       	15395997	        77.92 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_largeish_int-10    	14214717	        84.11 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_float-10           	 9016212	       133.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_byte_slice-10      	13968756	        85.88 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/single_duration-10        	10588659	       113.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/two_values-10             	12969648	        93.72 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/four_values-10            	 9006982	       136.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkLoggers/zerolog/eight_values-10           	 4979397	       239.5 ns/op	       0 B/op	       0 allocs/op
@mark-rushakoff mark-rushakoff requested a review from a team as a code owner February 24, 2023 18:27
@github-actions github-actions bot added the C:log label Feb 24, 2023
@julienrbrt julienrbrt merged commit 747c29e into main Feb 24, 2023
@julienrbrt julienrbrt deleted the mr/log-benchmark branch February 24, 2023 18:54
@alexanderbez
Copy link
Contributor

Nice, thanks @mark-rushakoff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants