1cf75b0 perf: optimize reverse NAT lookup with O(1) map instead of O(n) iteration
5977667 Merge branch 'fosrl:main' into optimize-reverse-nat-lookup
📊 Changes
1 file changed (+43 additions, -15 deletions)
View changed files
📝netstack2/proxy.go (+43 -15)
📄 Description
Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
Description
Replace O(n) linear search through NAT table with O(1) reverse lookup map for reply packet NAT translation.
Changes:
Add reverseConnKey type for reverse NAT lookups
Add reverseNatTable map to ProxyHandler for O(1) lookups
Populate both forward and reverse maps when creating NAT entries
Replace iteration-based reverse lookup with direct map access
Performance:
O(n) → O(1) complexity for reverse NAT lookups
Eliminates lock-held iteration on every reply packet
Removes string comparisons from hot path
Expected 10-50x improvement for reverse NAT lookups
This addresses Critical from performance analysis where reply path was walking the entire NAT table to find original mapping.
How to test?
Purely internal optimization, instead of walking the entire natTable every time to find where to reverse too. We create a map that is indexed by the reverse fields which stores the same netState data from the forward natTable.
🔄 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/fosrl/newt/pull/205
**Author:** [@LaurenceJJones](https://github.com/LaurenceJJones)
**Created:** 12/16/2025
**Status:** ✅ Merged
**Merged:** 3/3/2026
**Merged by:** [@oschwartz10612](https://github.com/oschwartz10612)
**Base:** `dev` ← **Head:** `optimize-reverse-nat-lookup`
---
### 📝 Commits (2)
- [`1cf75b0`](https://github.com/fosrl/newt/commit/1cf75b00ff8022832dc4d4c9f2915fa87a5d5e6c) perf: optimize reverse NAT lookup with O(1) map instead of O(n) iteration
- [`5977667`](https://github.com/fosrl/newt/commit/5977667291917aaf623a301da11601345b2d32dd) Merge branch 'fosrl:main' into optimize-reverse-nat-lookup
### 📊 Changes
**1 file changed** (+43 additions, -15 deletions)
<details>
<summary>View changed files</summary>
📝 `netstack2/proxy.go` (+43 -15)
</details>
### 📄 Description
## Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
## Description
Replace O(n) linear search through NAT table with O(1) reverse lookup map for reply packet NAT translation.
Changes:
- Add reverseConnKey type for reverse NAT lookups
- Add reverseNatTable map to ProxyHandler for O(1) lookups
- Populate both forward and reverse maps when creating NAT entries
- Replace iteration-based reverse lookup with direct map access
Performance:
- O(n) → O(1) complexity for reverse NAT lookups
- Eliminates lock-held iteration on every reply packet
- Removes string comparisons from hot path
- Expected 10-50x improvement for reverse NAT lookups
This addresses Critical from performance analysis where reply path was walking the entire NAT table to find original mapping.
## How to test?
Purely internal optimization, instead of walking the entire natTable every time to find where to reverse too. We create a map that is indexed by the reverse fields which stores the same netState data from the forward natTable.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/fosrl/newt/pull/205
Author: @LaurenceJJones
Created: 12/16/2025
Status: ✅ Merged
Merged: 3/3/2026
Merged by: @oschwartz10612
Base:
dev← Head:optimize-reverse-nat-lookup📝 Commits (2)
1cf75b0perf: optimize reverse NAT lookup with O(1) map instead of O(n) iteration5977667Merge branch 'fosrl:main' into optimize-reverse-nat-lookup📊 Changes
1 file changed (+43 additions, -15 deletions)
View changed files
📝
netstack2/proxy.go(+43 -15)📄 Description
Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
Description
Replace O(n) linear search through NAT table with O(1) reverse lookup map for reply packet NAT translation.
Changes:
Performance:
This addresses Critical from performance analysis where reply path was walking the entire NAT table to find original mapping.
How to test?
Purely internal optimization, instead of walking the entire natTable every time to find where to reverse too. We create a map that is indexed by the reverse fields which stores the same netState data from the forward natTable.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.