Hi,
V2 onions are a truncated SHA1. Doing an entire hash is expensive.
V3 onions are an ed25519 key plus a suffix. So if you're just looking for a prefix, you can choose a random value. Then increment by the basepoint until you find the prefix you want. (This is a relatively cheap operation, because you're just adding 255-bit numbers.)
You can save the expensive suffix calculations for the final candidate keys.
Here's one implementation: https://github.com/Yawning/horse25519/blob/master/src/horse25519.c#L209
This is a summary: there are a few important details to get right, like key masking and security.
T