Why does the fd table in wasi-common use a HashMap
instead of Vec<Option<_>>
? This requires hashing the key on every insert and lookup. For inserting stdin, stdout and stderr this takes a non-trivial amount of time when creating the WasiCtxt
.
I'm not 100% sure offhand, but it might have been related to the idea in CloudABI that file descriptor indices should be randomized
The idea in CloudABI is to catch race conditions in user code that assumes eg. calling open
twice will get sequential file descriptor indices. POSIX specifies that one should always get the lowest unallocate index, but in the presence of threads, another thread might call open
in between.
It's a clever idea, but I don't think it's something we'll want to do as we migrate to interface types.
So unless there are other reasons, I think it'd ok to switch to Vec<Option<_>>
at this point.
yep there's no particular good reason, we never bothered optimizing it and I would be happy to review a PR to add optimizations
Last updated: Nov 22 2024 at 16:03 UTC