[PR #5362] [MERGED] perf(xray): compile log/traffic regexps once at package scope #5857

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5362
Author: @n0ctal
Created: 6/15/2026
Status: ✅ Merged
Merged: 6/20/2026
Merged by: @Mahyardana

Base: main ← Head: pr-0010-hoist-xray-regexps


📝 Commits (2)

  • f325ec1 perf(xray): compile log/traffic regexps once at package scope
  • 296f9f3 Merge branch 'main' into pr-0010-hoist-xray-regexps

📊 Changes

2 files changed (+15 additions, -7 deletions)

View changed files

📝 internal/xray/api.go (+7 -3)
📝 internal/xray/log_writer.go (+8 -4)

📄 Description

Summary

Compiles the log and traffic regexps once at package scope instead of on every call.

Why

GetTraffic recompiled two stats regexps on every traffic-stats tick, and LogWriter.Write recompiled two more on every log line — wasted work on hot paths.

Scope

  • hoists trafficRegex / clientTrafficRegex and crashRegex / logLineRegex to package-level vars
  • patterns are identical; no behavior change

Validation

  • xray package tests pass
  • go build / go vet clean

Risk

Low. Pure refactor — the regex patterns are unchanged.


🔄 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/5362 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/15/2026 **Status:** ✅ Merged **Merged:** 6/20/2026 **Merged by:** [@Mahyardana](https://github.com/Mahyardana) **Base:** `main` ← **Head:** `pr-0010-hoist-xray-regexps` --- ### 📝 Commits (2) - [`f325ec1`](https://github.com/MHSanaei/3x-ui/commit/f325ec17504648113534f5fed8b56b4313c82fa8) perf(xray): compile log/traffic regexps once at package scope - [`296f9f3`](https://github.com/MHSanaei/3x-ui/commit/296f9f3b6485aa804a6863b22ff5c4d18e057224) Merge branch 'main' into pr-0010-hoist-xray-regexps ### 📊 Changes **2 files changed** (+15 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `internal/xray/api.go` (+7 -3) 📝 `internal/xray/log_writer.go` (+8 -4) </details> ### 📄 Description ## Summary Compiles the log and traffic regexps once at package scope instead of on every call. ## Why `GetTraffic` recompiled two stats regexps on every traffic-stats tick, and `LogWriter.Write` recompiled two more on every log line — wasted work on hot paths. ## Scope - hoists `trafficRegex` / `clientTrafficRegex` and `crashRegex` / `logLineRegex` to package-level vars - patterns are identical; no behavior change ## Validation - `xray` package tests pass - `go build` / `go vet` clean ## Risk Low. Pure refactor — the regex patterns are unchanged. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:35 +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#5857
No description provided.