Stream: wasi

Topic: wasi-common fd table


view this post on Zulip bjorn3 (Feb 11 2022 at 19:49):

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.

view this post on Zulip Dan Gohman (Feb 11 2022 at 19:50):

I'm not 100% sure offhand, but it might have been related to the idea in CloudABI that file descriptor indices should be randomized

view this post on Zulip Dan Gohman (Feb 11 2022 at 19:53):

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.

view this post on Zulip Dan Gohman (Feb 11 2022 at 19:56):

It's a clever idea, but I don't think it's something we'll want to do as we migrate to interface types.

view this post on Zulip Dan Gohman (Feb 11 2022 at 19:56):

So unless there are other reasons, I think it'd ok to switch to Vec<Option<_>> at this point.

view this post on Zulip Pat Hickey (Feb 14 2022 at 19:15):

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