Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

feat: Cache glab env config to improve overall command performance #146

Merged
merged 1 commit into from Aug 19, 2020

Conversation

pgollangi
Copy link
Contributor

@pgollangi pgollangi commented Aug 19, 2020

Cache glab env config which avoids loading env file from file system which in turn improves overall command performance

Description
Have a map of env config on first load which will used for all subsequent environment searches.

Related Issue
Closes #144

Motivation and Context

How Has This Been Tested?
Benchmarks without cache (bench-before.txt):

BenchmarkGetEnv-4   	   50974	     23479 ns/op	     816 B/op	       6 allocs/op
BenchmarkGetEnv-4   	   51392	     23192 ns/op	     816 B/op	       6 allocs/op
BenchmarkGetEnv-4   	   51847	     24126 ns/op	     816 B/op	       6 allocs/op
BenchmarkGetEnv-4   	   51861	     23541 ns/op	     816 B/op	       6 allocs/op
BenchmarkGetEnv-4   	   51854	     23891 ns/op	     816 B/op	       6 allocs/op

Benchmarks with cache (bench-after.txt):

BenchmarkGetEnv-4   	92289234	        12.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetEnv-4   	100000000	        12.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetEnv-4   	85945108	        12.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetEnv-4   	92740719	        12.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetEnv-4   	92294202	        12.5 ns/op	       0 B/op	       0 allocs/op

Overall improvement is almost 100%:

$ benchstat bench-before.txt bench-after.txt
name      old time/op    new time/op    delta
GetEnv-4    23.6µs ± 2%     0.0µs ± 2%   -99.95%  (p=0.008 n=5+5)

name      old alloc/op   new alloc/op   delta
GetEnv-4      816B ± 0%        0B       -100.00%  (p=0.008 n=5+5)

name      old allocs/op  new allocs/op  delta
GetEnv-4      6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@pull-assistant
Copy link

Score: 1.00

Best reviewed: commit by commit


Optimal code review plan

     feat: Cache glab env config to improve overall command performance

Powered by Pull Assistant. Last update 7f1ccaf ... 7f1ccaf. Read the comment docs.

@profclems
Copy link
Owner

goos: linux
goarch: amd64
pkg: glab/internal/config
BenchmarkGetEnv-4       83589975                14.0 ns/op
BenchmarkGetEnv-4       83691345                14.7 ns/op
BenchmarkGetEnv-4       85224246                14.0 ns/op
BenchmarkGetEnv-4       84176131                14.0 ns/op
BenchmarkGetEnv-4       78762896                16.2 ns/op

This is a great performance improvement. It is very negligible

@profclems profclems merged commit 3f3a434 into profclems:trunk Aug 19, 2020
@profclems
Copy link
Owner

@all-contributors please add @pgollangi for maintenance

@allcontributors
Copy link
Contributor

@profclems

I've put up a pull request to add @pgollangi! 🎉

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

Successfully merging this pull request may close these issues.

Cache glab env configuration to avoid reading from FileSystem everytime
2 participants