[PR #28] [MERGED] add ip/host lookup hashmap #37

Closed
opened 2026-03-02 05:08:16 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/goodhosts/hostsfile/pull/28
Author: @luthermonson
Created: 12/2/2021
Status: Merged
Merged: 12/2/2021
Merged by: @luthermonson

Base: mainHead: add-lookup


📝 Commits (2)

  • 946b651 add ip/host lookup hashmap to speedup and support multi location within the file
  • 4106b03 vendor

📊 Changes

37 files changed (+3923 additions, -279 deletions)

View changed files

📝 go.mod (+2 -0)
📝 go.sum (+12 -0)
📝 hosts.go (+130 -70)
📝 hosts_test.go (+157 -174)
📝 slice.go (+31 -5)
📝 slice_test.go (+18 -30)
vendor/github.com/corpix/uarand/.gitignore (+2 -0)
vendor/github.com/corpix/uarand/.travis.yml (+3 -0)
vendor/github.com/corpix/uarand/LICENSE (+24 -0)
vendor/github.com/corpix/uarand/Makefile (+32 -0)
vendor/github.com/corpix/uarand/README.md (+38 -0)
vendor/github.com/corpix/uarand/shell.nix (+17 -0)
vendor/github.com/corpix/uarand/uarand.go (+63 -0)
vendor/github.com/corpix/uarand/useragents.go (+1735 -0)
vendor/github.com/icrowley/fake/.gitignore (+26 -0)
vendor/github.com/icrowley/fake/.go-makefile.json (+11 -0)
vendor/github.com/icrowley/fake/.travis.yml (+11 -0)
vendor/github.com/icrowley/fake/LICENSE (+22 -0)
vendor/github.com/icrowley/fake/Makefile (+48 -0)
vendor/github.com/icrowley/fake/README.md (+90 -0)

...and 17 more files

📄 Description

Problem: after benchmarking it turns out this package doesn't scale once the entries increase per https://github.com/goodhosts/cli/issues/28

Fix: This PR changes from the over reliance of the slice lookup method to a hashmap for the ips and hosts so we can pull position instantly. This fix is thread safe as confirmed by the benchmarks and modifies the API especially with hose hosts need to be pointers now due to the mutex having to be maintained for thread safety.

Extras:

  • rewrote tests to use asserts instead of rando if/else stuff
  • to keep track of the lookup indexes we have to use the exported funcs to add Lines to the Hosts so added AddRaw to help facility anyone using the NewHostLine() stuff.
  • NewHosts/NewCustomHosts now pass back a pointer
  • Added benchmarks

Related Issues:
Should fix https://github.com/goodhosts/cli/issues/25


🔄 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/goodhosts/hostsfile/pull/28 **Author:** [@luthermonson](https://github.com/luthermonson) **Created:** 12/2/2021 **Status:** ✅ Merged **Merged:** 12/2/2021 **Merged by:** [@luthermonson](https://github.com/luthermonson) **Base:** `main` ← **Head:** `add-lookup` --- ### 📝 Commits (2) - [`946b651`](https://github.com/goodhosts/hostsfile/commit/946b651a0a519a050e3a83e8a59a60775e982d9f) add ip/host lookup hashmap to speedup and support multi location within the file - [`4106b03`](https://github.com/goodhosts/hostsfile/commit/4106b03799ca3cbc6af9f2617541efe5a47550f9) vendor ### 📊 Changes **37 files changed** (+3923 additions, -279 deletions) <details> <summary>View changed files</summary> 📝 `go.mod` (+2 -0) 📝 `go.sum` (+12 -0) 📝 `hosts.go` (+130 -70) 📝 `hosts_test.go` (+157 -174) 📝 `slice.go` (+31 -5) 📝 `slice_test.go` (+18 -30) ➕ `vendor/github.com/corpix/uarand/.gitignore` (+2 -0) ➕ `vendor/github.com/corpix/uarand/.travis.yml` (+3 -0) ➕ `vendor/github.com/corpix/uarand/LICENSE` (+24 -0) ➕ `vendor/github.com/corpix/uarand/Makefile` (+32 -0) ➕ `vendor/github.com/corpix/uarand/README.md` (+38 -0) ➕ `vendor/github.com/corpix/uarand/shell.nix` (+17 -0) ➕ `vendor/github.com/corpix/uarand/uarand.go` (+63 -0) ➕ `vendor/github.com/corpix/uarand/useragents.go` (+1735 -0) ➕ `vendor/github.com/icrowley/fake/.gitignore` (+26 -0) ➕ `vendor/github.com/icrowley/fake/.go-makefile.json` (+11 -0) ➕ `vendor/github.com/icrowley/fake/.travis.yml` (+11 -0) ➕ `vendor/github.com/icrowley/fake/LICENSE` (+22 -0) ➕ `vendor/github.com/icrowley/fake/Makefile` (+48 -0) ➕ `vendor/github.com/icrowley/fake/README.md` (+90 -0) _...and 17 more files_ </details> ### 📄 Description Problem: after benchmarking it turns out this package doesn't scale once the entries increase per https://github.com/goodhosts/cli/issues/28 Fix: This PR changes from the over reliance of the slice lookup method to a hashmap for the ips and hosts so we can pull position instantly. This fix is thread safe as confirmed by the benchmarks and modifies the API especially with hose hosts need to be pointers now due to the mutex having to be maintained for thread safety. Extras: * rewrote tests to use asserts instead of rando if/else stuff * to keep track of the lookup indexes we have to use the exported funcs to add Lines to the Hosts so added AddRaw to help facility anyone using the NewHostLine() stuff. * NewHosts/NewCustomHosts now pass back a pointer * Added benchmarks Related Issues: Should fix https://github.com/goodhosts/cli/issues/25 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 05:08:16 +03:00
Sign in to join this conversation.
No labels
pull-request
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
starred/hostsfile#37
No description provided.