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

chore: optimise function config.ConfigKeyToEnv #475

Merged
merged 2 commits into from
May 21, 2024
Merged

Conversation

mihir20
Copy link
Contributor

@mihir20 mihir20 commented May 21, 2024

Description

In a 1 hour profile config.ConfigKeyToEnv is taking near to 8.4minutes of execution, which can be seen from flame graph.
image

Internally this function is using regex which is we can be replaced and performance can be optimised. After replacing regex with simple for loops we can see improvements in the performance. attaching benchmark results here:

Old Code:  
BenchmarkConfigKeyToEnv-12    	 1287674	       922.6 ns/op	     265 B/op	      10 allocs/op
New Code: 
BenchmarkConfigKeyToEnv-12    	 9455137	       118.8 ns/op	      56 B/op	       3 allocs/op

Linear Ticket

https://linear.app/rudderstack/issue/PIPE-1103/optimise-function-configconfigkeytoenv-in-rudder-go-kit

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice one 👍

The only difference I could spot is that your upper case function returns true for empty strings, but that was not the case with the old version.

It shouldn't be a problem though 👍

Copy link
Member

@Sidddddarth Sidddddarth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!
Adding some more test cases around ConfigKeyToEnv would be nice.

@cisse21 cisse21 enabled auto-merge (squash) May 21, 2024 12:44
Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.90%. Comparing base (bc95a3f) to head (3a9cb41).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #475      +/-   ##
==========================================
- Coverage   78.98%   78.90%   -0.08%     
==========================================
  Files          90       95       +5     
  Lines        6747     6793      +46     
==========================================
+ Hits         5329     5360      +31     
- Misses       1153     1160       +7     
- Partials      265      273       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cisse21 cisse21 merged commit 0cbe3e2 into main May 21, 2024
12 checks passed
@cisse21 cisse21 deleted the mihir/pipe-981 branch May 21, 2024 13:14
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.

4 participants