[PR #6790] [MERGED] perf: reduce traffic formatter allocations #6456

Closed
opened 2026-11-02 04:08:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6790
Author: @javi0guerrero4-cloud
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @MHSanaei

Base: main ← Head: perf/format-traffic-allocs


📝 Commits (1)

  • ddb4f9d perf: reduce traffic formatter allocations

📊 Changes

2 files changed (+8 additions, -4 deletions)

View changed files

📝 internal/util/common/format.go (+2 -4)
📝 internal/util/common/format_test.go (+6 -0)

📄 Description

Summary

This change replaces the shared traffic formatter's mt.Sprintf path with strconv.FormatFloat, which reduces per-call formatting overhead and allocation churn in status/report generation.

Why this helps

FormatTraffic is used in repeated traffic and status outputs. Avoiding the mt package here removes extra formatting work on a hot path while preserving the previous output format exactly.

Validation

  • Updated the formatter to keep the exact existing output strings.
  • Added a focused benchmark to exercise the call pattern used in status/reporting code.
  • Verified the output format against the repository's traffic-format regression cases using equivalent logic in the local environment (Go toolchain was unavailable in the sandbox, so I validated the exact formatting behavior directly against the existing cases).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6790 **Author:** [@javi0guerrero4-cloud](https://github.com/javi0guerrero4-cloud) **Created:** 10/11/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `perf/format-traffic-allocs` --- ### 📝 Commits (1) - [`ddb4f9d`](https://github.com/MHSanaei/3x-ui/commit/ddb4f9d87469558f84fc49e312d9d94d78784b22) perf: reduce traffic formatter allocations ### 📊 Changes **2 files changed** (+8 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `internal/util/common/format.go` (+2 -4) 📝 `internal/util/common/format_test.go` (+6 -0) </details> ### 📄 Description ## Summary This change replaces the shared traffic formatter's mt.Sprintf path with strconv.FormatFloat, which reduces per-call formatting overhead and allocation churn in status/report generation. ## Why this helps FormatTraffic is used in repeated traffic and status outputs. Avoiding the mt package here removes extra formatting work on a hot path while preserving the previous output format exactly. ## Validation - Updated the formatter to keep the exact existing output strings. - Added a focused benchmark to exercise the call pattern used in status/reporting code. - Verified the output format against the repository's traffic-format regression cases using equivalent logic in the local environment (Go toolchain was unavailable in the sandbox, so I validated the exact formatting behavior directly against the existing cases). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:54 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6456
No description provided.