Skip to content

Add borsh serialization support - #313

Merged
cuviper merged 7 commits into
indexmap-rs:masterfrom
namada-net:heliax/borsh-support
Feb 29, 2024
Merged

cuviper merged 7 commits into
indexmap-rs:masterfrom
namada-net:heliax/borsh-support

Conversation

@sug0

@sug0 sug0 commented Feb 20, 2024

Copy link
Copy Markdown
Contributor

Add support to serialize maps and sets with borsh.

@sug0
sug0 force-pushed the heliax/borsh-support branch from e273293 to c3909d5 Compare February 20, 2024 14:38
@sug0
sug0 marked this pull request as draft February 20, 2024 14:52
@sug0
sug0 marked this pull request as ready for review February 20, 2024 14:57
Comment thread Cargo.toml Outdated
Comment thread Cargo.toml Outdated
Comment thread src/borsh.rs Outdated
Comment thread src/borsh.rs Outdated
@sug0
sug0 marked this pull request as draft February 21, 2024 10:43
@sug0
sug0 force-pushed the heliax/borsh-support branch from c3909d5 to db551fa Compare February 21, 2024 23:03
@sug0
sug0 requested a review from cuviper February 21, 2024 23:05
@sug0
sug0 marked this pull request as ready for review February 21, 2024 23:05
@sug0
sug0 force-pushed the heliax/borsh-support branch 2 times, most recently from 149d560 to 88a5692 Compare February 21, 2024 23:22
Comment thread Cargo.toml Outdated
Comment thread src/borsh.rs
Comment thread src/borsh.rs
@sug0
sug0 force-pushed the heliax/borsh-support branch from 88a5692 to 9a0ca23 Compare February 26, 2024 10:18
@sug0
sug0 requested a review from cuviper February 26, 2024 10:18
@sug0
sug0 marked this pull request as draft February 26, 2024 12:33
@sug0

sug0 commented Feb 26, 2024 •

Copy link
Copy Markdown
Contributor Author

@cuviper the new deserialization code in spite of working correctly, introduced some exploits related with OOM errors. I'm inclined to rollback to Vec's borsh deserialization code, considering the gains in performance of the new approach are very minute anyway, and their deserialization code already solves the problem at hand. lmk what you think

@cuviper

cuviper commented Feb 26, 2024

Copy link
Copy Markdown
Member

introduced some exploits related with OOM errors.

Please explain this! If there's an "exploit" footgun here, it needs to be commented at the very least.

@sug0

sug0 commented Feb 26, 2024

Copy link
Copy Markdown
Contributor Author

@cuviper hm the problem is this deserialization code I wrote is blindly allocating a buffer for incoming items from a stream. the deserialization code in borsh for collections already guards against OOM related issues by limiting the size of allocations (possibly why it's occasionally slower in the benches I ran).

I'll revert the deserialization code to use Vec::deserialize_from_reader as I had before

@cuviper

cuviper commented Feb 26, 2024

Copy link
Copy Markdown
Member

Oh, I see -- I should really add limits to serde size_hint() deserializers as well, as they do in their own impls.

@sug0
sug0 force-pushed the heliax/borsh-support branch from 9a0ca23 to 7add3e1 Compare February 27, 2024 09:57
@sug0
sug0 marked this pull request as ready for review February 27, 2024 09:57

@cuviper cuviper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CI failed on MSRV --all-features, since borsh wants 1.66, so I guess we need to reduce that job to the list of features that do work with 1.63. (I don't want to raise MSRV just for an optional feature.)

Comment thread src/borsh.rs Outdated
Comment thread src/borsh.rs Outdated
Comment thread src/borsh.rs Outdated
@cuviper

cuviper commented Feb 28, 2024

Copy link
Copy Markdown
Member

Your branch is not open to maintainer pushes, so I put suggested changes in my fork:
namada-net/indexmap@heliax/borsh-support...cuviper:indexmap:borsh-support

@sug0

sug0 commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

@cuviper thanks for the patches! I've included them in this branch

@sug0
sug0 requested a review from cuviper February 29, 2024 12:54
@sug0
sug0 force-pushed the heliax/borsh-support branch from e4aa6cf to b81a4d2 Compare February 29, 2024 12:59
@sug0

sug0 commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

rebased on 2.2.4

@cuviper
cuviper added this pull request to the merge queue Feb 29, 2024
Merged via the queue into indexmap-rs:master with commit c934ace Feb 29, 2024
@sug0
sug0 deleted the heliax/borsh-support branch February 29, 2024 19:26
@cuviper

cuviper commented Feb 29, 2024

Copy link
Copy Markdown
Member

This has been published in 2.2.5!

@sug0

sug0 commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

sweet. thanks!

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.

2 participants