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

Compiling the regular expression every time it is consumed is redundant. #2662

Closed
qshuai opened this issue Oct 8, 2023 · 0 comments · Fixed by #2663
Closed

Compiling the regular expression every time it is consumed is redundant. #2662

qshuai opened this issue Oct 8, 2023 · 0 comments · Fixed by #2663

Comments

@qshuai
Copy link
Contributor

qshuai commented Oct 8, 2023

Description

The target code:

sarama/utils.go

Line 302 in 44f6db5

if !regexp.MustCompile(pattern).MatchString(s) {

The function regexp.MustCompile(pattern) will comiple the specified pattern when consuming every time. It is not CPU friendly.

The following is the part of CPU profile(Flame Graph) in production environment. It accounts for 7.6% in CPU usage and should be optimized.
cpu profile

qshuai added a commit to qshuai/sarama that referenced this issue Oct 8, 2023
qshuai added a commit to qshuai/sarama that referenced this issue Oct 11, 2023
dnwe pushed a commit to qshuai/sarama that referenced this issue Oct 11, 2023
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 a pull request may close this issue.

1 participant