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

🚀 Performance improvements #2838

Merged
merged 99 commits into from
Feb 9, 2024
Merged

🚀 Performance improvements #2838

merged 99 commits into from
Feb 9, 2024

Conversation

Fenny
Copy link
Member

@Fenny Fenny commented Feb 8, 2024

  • Replace Sprintf with bytebufferpool in ctx.String()
  • Replace Sprintfwith bytebufferpool in middleware/logger#default
  • Use optimized utils.ToString and avoid once.Do in log
// OLD middleware/logger Sprintf
Benchmark_Logger/DefaultFormat-24                2205628               545.0 ns/op           208 B/op          8 allocs/op
Benchmark_Logger/DefaultFormat-24                2227387               539.9 ns/op           208 B/op          8 allocs/op
Benchmark_Logger/DefaultFormat-24                2189026               542.1 ns/op           208 B/op          8 allocs/op
Benchmark_Logger/DefaultFormat-24                2223640               548.8 ns/op           208 B/op          8 allocs/op

// NEW middleware/logger bytebufferpool
Benchmark_Logger/DefaultFormat-24                6137152               192.5 ns/op            16 B/op          2 allocs/op
Benchmark_Logger/DefaultFormat-24                6331454               188.7 ns/op            16 B/op          2 allocs/op
Benchmark_Logger/DefaultFormat-24                6390472               188.2 ns/op            16 B/op          2 allocs/op
Benchmark_Logger/DefaultFormat-24                6268698               189.1 ns/op            16 B/op          2 allocs/op
// OLD ctx.String()
Benchmark_Ctx_String-24          3846717               318.0 ns/op           152 B/op          8 allocs/op
Benchmark_Ctx_String-24          3780208               315.9 ns/op           152 B/op          8 allocs/op
Benchmark_Ctx_String-24          3627513               315.1 ns/op           152 B/op          8 allocs/op
Benchmark_Ctx_String-24          3712863               317.4 ns/op           152 B/op          8 allocs/op

// NEW ctx.String()
Benchmark_Ctx_String-24          8131666               149.3 ns/op            96 B/op          5 allocs/op
Benchmark_Ctx_String-24          7626406               148.3 ns/op            96 B/op          5 allocs/op
Benchmark_Ctx_String-24          8194621               149.2 ns/op            96 B/op          5 allocs/op
Benchmark_Ctx_String-24          8297750               156.6 ns/op            96 B/op          5 allocs/op
// OLD log
BenchmarkLogfKeyAndValues/test_logf_with_debug_level_and_key-values-24         	 7323432	       153.8 ns/op	      89 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_info_level_and_key-values-24          	 8171703	       144.5 ns/op	      81 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_warn_level_and_key-values-24          	 8207860	       142.8 ns/op	      81 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_format_and_key-values-24              	 7500332	       159.1 ns/op	     135 B/op	       2 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_one_key-24                            	10024760	       131.0 ns/op	     155 B/op	       2 allocs/op

// NEW log
BenchmarkLogfKeyAndValues/test_logf_with_debug_level_and_key-values-24         	13797813	        77.42 ns/op	      77 B/op	       0 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_info_level_and_key-values-24          	15375350	        75.43 ns/op	      73 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_warn_level_and_key-values-24          	14926300	        75.28 ns/op	      75 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_format_and_key-values-24              	12860275	        90.27 ns/op	     134 B/op	       2 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_one_key-24                            	15649615	        74.98 ns/op	     100 B/op	       1 allocs/op

Fenny and others added 30 commits May 24, 2020 15:21
- fix expected cookie values in tests
Co-Authored-By: Thomas van Vugt <thomasvvugt@users.noreply.github.com>
Co-Authored-By: Thomas van Vugt <thomasvvugt@users.noreply.github.com>
Co-Authored-By: Queru <pascal@queru.net>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
# Conflicts:
#	ctx.go
#	router.go
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: RW <renewerner87@googlemail.com>
ReneWerner87 and others added 5 commits November 20, 2020 11:43
Use optimized `utils.ToString` and avoid `once.Do`

**Before**
```
BenchmarkLogfKeyAndValues/test_logf_with_debug_level_and_key-values-24         	 7323432	       153.8 ns/op	      89 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_info_level_and_key-values-24          	 8171703	       144.5 ns/op	      81 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_warn_level_and_key-values-24          	 8207860	       142.8 ns/op	      81 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_format_and_key-values-24              	 7500332	       159.1 ns/op	     135 B/op	       2 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_one_key-24                            	10024760	       131.0 ns/op	     155 B/op	       2 allocs/op
```
**After**
```
BenchmarkLogfKeyAndValues/test_logf_with_debug_level_and_key-values-24         	13797813	        77.42 ns/op	      77 B/op	       0 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_info_level_and_key-values-24          	15375350	        75.43 ns/op	      73 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_warn_level_and_key-values-24          	14926300	        75.28 ns/op	      75 B/op	       1 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_format_and_key-values-24              	12860275	        90.27 ns/op	     134 B/op	       2 allocs/op
BenchmarkLogfKeyAndValues/test_logf_with_one_key-24                            	15649615	        74.98 ns/op	     100 B/op	       1 allocs/op
```
@Fenny Fenny changed the title Small improvements 🚀 Small improvements Feb 8, 2024
@Fenny Fenny changed the title 🚀 Small improvements 🚀 Small improvement Feb 9, 2024
@Fenny Fenny self-assigned this Feb 9, 2024
@Fenny Fenny added this to the v3 milestone Feb 9, 2024
@Fenny Fenny changed the title 🚀 Small improvement 🚀 Micro improvements Feb 9, 2024
# Original fn using Sprintf
Benchmark_Ctx_String-24          3846717               318.0 ns/op           152 B/op          8 allocs/op
Benchmark_Ctx_String-24          3780208               315.9 ns/op           152 B/op          8 allocs/op
Benchmark_Ctx_String-24          3627513               315.1 ns/op           152 B/op          8 allocs/op
Benchmark_Ctx_String-24          3712863               317.4 ns/op           152 B/op          8 allocs/op

// Modified using bytebufferpool
Benchmark_Ctx_String-24          8131666               149.3 ns/op            96 B/op          5 allocs/op
Benchmark_Ctx_String-24          7626406               148.3 ns/op            96 B/op          5 allocs/op
Benchmark_Ctx_String-24          8194621               149.2 ns/op            96 B/op          5 allocs/op
Benchmark_Ctx_String-24          8297750               156.6 ns/op            96 B/op          5 allocs/op
@Fenny Fenny changed the title 🚀 Micro improvements 🚀 Performance improvements Feb 9, 2024
@ReneWerner87
Copy link
Member

ReneWerner87 commented Feb 9, 2024

thx you are awesome

just 2 linter errors and the unneeded comments are pending

  • fix linter errors
  • remove old comments

@ReneWerner87 ReneWerner87 merged commit 2b03f47 into gofiber:main Feb 9, 2024
14 checks passed
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.

3 participants