v0.9.0 brings many performance optimizations. By removing duplicate organization names, the embeded dataset was minimized. When exploring ways to optimize func Find the storage model changed from a slice to a single string const. Minimizing memory allocations usually helps performance a lot. In that area 0 allocations was reached for both Find and Lookup. The API surface did increase slightly by introducing a new type Assignment, but the readability and usability for callers is worth it.
| benchmark | v0.8.0 | v0.9.0 | change |
|---|---|---|---|
| Find ns/op | 938384 | 140020 | 6.7x |
| Find B/op | 12424 | 0 | |
| Find allocs/op | 1553 | 0 | |
| Lookup ns/op | 969.3 | 203.1 | 4.8x |
| Lookup B/op | 216 | 0 | |
| Lookup allocs/op | 18 | 0 | |
| dataset size | 2497999 B | 2223111 B | -11% |
| binary size (cmd/lmac) | 4404492 B | 3940293 B | -10.5% |
| full build time | ~2.6s | ~2.2s | -15% |
$ go install sogvin.com/lmac/cmd/lmac@latest
All returns every MA-L, MA-M and MA-S assignment in the database.
Find the assignments whose organization contains substr.
for a := range lmac.Find("Dell") {
fmt.Println(a, a.Organization())
}
Lookup returns the registered organization for the given MAC address.
Allowed formats:
00:00:00:00:00:aa 00-00-00-00-00-aa 0000000000aa
Partial MAC addresses are also allowed:
00:01:22 00-01-22 000122
The values are case-insensitive.
An Assignment is a MAC address block the IEEE has assigned to an organization, packed into a uint64. Bit layout:
0x001bc504b0025f13
0x001bc504b00 prefix
2 registry tag
5f13 org index
Masking off tag and org index leaves the 48 bit MAC prefix in bits 63..16, the form parse returns and AppendText formats. Keeping the prefix in the high bits makes assignments sort by prefix, which containing relies on.
AppendText appends the assignment prefix to dst as upper case hex digits separated by : every two digits, six digits for MA-L, seven for MA-M and nine for MA-S. The odd registries end in a half byte, eg. 00:55:8D:0. The error is always nil, it implements encoding.TextAppender.
Organization returns the organization of the assignment, empty string if the org index is unknown.
Registry returns the assignment's registry, "ma-l", "ma-m" or "ma-s".
String returns the assignment prefix as upper case hex digits separated by : every two digits, eg. 00:1B:C5:04:B. The number of digits depends on the registry, see AppendText.
Gregory Vinčić