Skip to content

[client] Improve userspace filter logging performance #4221

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

Merged
merged 2 commits into from
Jul 31, 2025
Merged

Conversation

lixmal
Copy link
Collaborator

@lixmal lixmal commented Jul 25, 2025

Describe your changes

This improves logging performance when logs are off by eliminating the variadic function call.

Test Case Variadic LogN Improvement
2 Args - Disabled 72.75ns, 32B, 1 alloc 0.85ns, 0B, 0 allocs 86x faster
2 Args - Enabled 102.2ns, 35B, 1 alloc 23.45ns, 0B, 0 allocs 4.4x faster
6 Args - Disabled 112.5ns, 96B, 1 alloc 0.85ns, 0B, 0 allocs 132x faster
6 Args - Enabled 124.9ns, 97B, 1 alloc 38ns, 0B, 0 allocs 3.3x faster

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

@Copilot Copilot AI review requested due to automatic review settings July 25, 2025 09:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves logging performance in the userspace filter by replacing variadic logging functions with fixed-argument variants. The changes eliminate the overhead of variadic function calls when logging is disabled, achieving significant performance improvements (80-135x faster for disabled logs, 3-5x faster for enabled logs).

  • Replaced variadic logger methods with numbered variants (Error1, Trace2, etc.) for different argument counts
  • Updated the logMessage struct to store individual arguments instead of a slice
  • Modified all call sites throughout the codebase to use the appropriate numbered logging methods

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
client/firewall/uspfilter/log/log.go Core logger implementation with new numbered methods and argument handling
client/firewall/uspfilter/log/log_test.go Updated benchmarks to use new numbered logging methods
client/firewall/uspfilter/nat.go Updated logging calls to use Error1 and Trace2 methods
client/firewall/uspfilter/forwarder/udp.go Updated all logging calls to use numbered variants
client/firewall/uspfilter/forwarder/tcp.go Updated all logging calls to use numbered variants
client/firewall/uspfilter/forwarder/icmp.go Updated all logging calls to use numbered variants
client/firewall/uspfilter/forwarder/endpoint.go Updated logging call to use Error1 method
client/firewall/uspfilter/filter.go Updated all logging calls to use numbered variants
client/firewall/uspfilter/conntrack/udp.go Updated logging calls to use numbered variants
client/firewall/uspfilter/conntrack/tcp.go Updated logging calls to use numbered variants
client/firewall/uspfilter/conntrack/icmp.go Updated logging calls to use numbered variants

Copy link

sonarqubecloud bot commented Jul 25, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.9% Duplication on New Code

See analysis details on SonarQube Cloud

@lixmal lixmal merged commit 71bb09d into main Jul 31, 2025
46 of 47 checks passed
@lixmal lixmal deleted the uspfilter-log-perf branch July 31, 2025 12:36
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 this pull request may close these issues.

2 participants