Skip to content

batch::get-many should parallel store.get - #55

Merged
danbugs merged 3 commits into
WebAssembly:mainfrom
devigned:get-many-fix
Aug 15, 2026
Merged

batch::get-many should parallel store.get#55
danbugs merged 3 commits into
WebAssembly:mainfrom
devigned:get-many-fix

Conversation

@devigned

@devigned devigned commented Nov 4, 2024

Copy link
Copy Markdown
Collaborator
get: func(key: string) -> result<option<list<u8>>, error>;

in store returns an option<list<u8>>, but

get-many: func(...) -> result<list<option<tuple<string, list<u8>>>>, error>;)

in batch returns list<option<tuple<string, list<u8>>>>. I would expect get-many to return result<list<tuple<string, option<list<u8>>>>, error>;.

Signed-off-by: David Justice <david@devigned.com>

@Mossaka Mossaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense to me.

Since this updates the APIs, can you bump the draft version up?

Comment thread wit/batch.wit
@thomastaylor312

Copy link
Copy Markdown
Collaborator

I can go either way on this. I think we may have had it the way you have it in this PR before, but I swapped it out because you have to return a copy of the key. For a batch request, that means even if you have no data to show, you have to return a new key (which could be quite large for some people). Since batch requests are big, this is where extra allocations of keys could matter. I swapped it to the option because it should be returned in the same order as passed in, so if you absolutely need to know which key you need, you can refer to that. Here are our options and the tradeoffs:

What you have in this PR:

list<tuple<string, option<list<u8>>>>

Advantages: Easiest to consume because you have each KV pair
Disadvantages: Extra allocation of every key that is passed in

Current:

list<option<tuple<string, list<u8>>>>

Advantages: No extra allocations of non-existent keys
Disadvantages: Awkward mapping back to initial list of keys if you need to know the missing key

Option 3

list<option<list<u8>>>

Advantages: No extra allocation of keys
Disadvantages: Required iterate over the list of keys and results together (which can be awkward/annoying in some languages)

So I think those are the options. After putting some thought into it here, I'd rather have option 3 to avoid all sorts of extra memory usage (and copying), but we should decide together what we'd prefer here

@ChihweiLHBird

ChihweiLHBird commented Jul 22, 2026

Copy link
Copy Markdown

@thomastaylor312 if we want "no extra allocations of non-existent keys", I think list<tuple<string, list<u8>>> would be a better option, where all non-existent keys are simply dropped. Or list<tuple<string, option<list<u8>>>> (this PR) is good too if we want to handle the case of data source (e.g., kv db) storing the key with an explicit value of null. We can then specify that all non-existent keys must be dropped and (key, none) entry can only be used for an explicit null.

I think the current one is the worst, because I can't think of any use case of having None in the list, list{None, None, None, ("my_key", "my_value")}

@ChihweiLHBird

ChihweiLHBird commented Jul 23, 2026

Copy link
Copy Markdown

Hi @danbugs @devigned @Mossaka, can we reconsider this PR for merging?

@ChihweiLHBird ChihweiLHBird mentioned this pull request Jul 30, 2026
Update the doc comment to make it explicit that the returned list
always contains one entry per requested key, with `none` for the
value if the key does not exist. Regenerate imports.md and
watch-service.md to match.
The v22 action fails because it looks for a pre-built binary at
tag `wit-bindgen-cli-0.32.0` which no longer exists. The v25
action uses cargo install with caching instead, which resolves
the tool from crates.io and works for any published version.

@danbugs danbugs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the doc comment as requested and also updated the wit-abi-up-to-date tooling version to get a passing CI. LGTM.

@danbugs
danbugs merged commit aa972c8 into WebAssembly:main Aug 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants