Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Perf] Use SmallVec for additional temporary allocations #4

Open
wants to merge 7 commits into
base: mainnet-staging
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
perf: use SmallVec in Identifier::parse
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
ljedrz committed Jun 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 24bef23ca05f1f5466d85a9c573feac5f214b204
5 changes: 5 additions & 0 deletions console/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -59,5 +59,10 @@ version = "1.0"
version = "1.0"
features = [ "preserve_order" ]

[dependencies.smallvec]
version = "1.11"
features = [ "const_new" ]
default-features = false

[dev-dependencies.bincode]
version = "1.3"
7 changes: 6 additions & 1 deletion console/program/src/data/identifier/parse.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@

use super::*;

use smallvec::SmallVec;

impl<N: Network> Parser for Identifier<N> {
/// Parses a string into an identifier.
///
@@ -60,8 +62,11 @@ impl<N: Network> FromStr for Identifier<N> {

// Note: The string bytes themselves are **not** little-endian. Rather, they are order-preserving
// for reconstructing the string when recovering the field element back into bytes.
let mut field_bits: SmallVec<[bool; 128]> = SmallVec::new();
identifier.as_bytes().write_bits_le(&mut field_bits);

Ok(Self(
Field::<N>::from_bits_le(&identifier.as_bytes().to_bits_le())?,
Field::<N>::from_bits_le(&field_bits)?,
u8::try_from(identifier.len()).or_halt_with::<N>("Identifier `from_str` exceeds maximum length"),
))
}