Micro-optimize transitive depencency hash calculation (#20798)
In small incrementals runs targeting a very large code base, the
`transitive_dep_hash` function used up to 9% of total CPU.
Micro-optimize it by avoiding json dump, dict construction and `hex()`
calls.
I'll verify that this helps after this has been merged, but the improved
performance (esp. without orjson) seems very likely.