Closed mcollina closed 4 years ago
@mcollina I think that is the generally accepted way to validate a string as an IPv6 address. Other methods involve feeding the string into a library that validates by converting the string to bytes and determining if the bytes are a valid address -- https://guava.dev/releases/19.0/api/docs/src-html/com/google/common/net/InetAddresses.html#line.167
Having looked into this, I am not able to reduce the complexity of this RegExp without sacrificing correctness, unfortunately.
We are investigating slow startup time in Fastify, and we identified this library as our primary bottleneck (see also https://github.com/epoberezkin/ajv/issues/995).
This is a flamegraph of the startup time. Apparently, the bottleneck is normalizing IPv6 addresses in https://github.com/garycourt/uri-js/blob/4f6f600fade03398c08adf2755c3a2ad66d31b3c/src/uri.ts#L175.
Note that that RegExp is extremely long:
This regexp is costly to evaluate at a 5-10ms each time on my machine (Node 10).
Do you think it's possible to simplify the above regexp so it's simpler and faster to execute?