oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.31k stars 2.69k forks source link

Implement DNS LRU cache based on TTL when c-ares is used #1746

Open Jarred-Sumner opened 1 year ago

Jarred-Sumner commented 1 year ago

c-ares does no caching which means repeated queries to the same hostnames will be slower than system dns

Unlike getaddrinfo, c-ares includes the TTL for the DNS query. That means we can do caching with it

Zig's standard library doesn't have an LRU we can just use. Maybe could wrap std.PriorityQueue but it's not precisely the same thing

wpaulino commented 3 weeks ago

Looks like we can get this for free by upgrading to c-ares v1.31.0: https://github.com/c-ares/c-ares/blob/063379049f9d43fc08bc74a7fe8639add88730ef/src/lib/ares_options.c#L458