Skip to content

Commit

Permalink
chore: Optimize code efficiency and update toolchain version (#1247)
Browse files Browse the repository at this point in the history
- Optimized memory usage by employing efficient cloning through the `clone_from` method in `compute_coeffs` and `build_frames` functions.
- Included the `#[allow(dead_code)]` attribute to the `CaseClause` struct and `Op` trait, to suppress possible warnings about unused codes.
- Enhanced constancy in the `lurk-metrics/src/lib.rs` by making the `LOCAL_SINK` instantiation constant.
- Upgraded the Rust toolchain channel from `1.76` to `1.78` in `rust-toolchain.toml`.
- Improved clarity and standard compliance by renaming the .cargo/config file to .cargo/config.toml.
  • Loading branch information
huitseeker authored Jun 1, 2024
1 parent 7657353 commit 7febc96
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion benches/common/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn compute_coeffs<F: LurkField>(store: &Store<F>) -> (usize, usize) {
let frame = step_func
.call_simple(&input, store, &lang, 0, &dummy_terminal())
.unwrap();
input = frame.output.clone();
input.clone_from(&frame.output);
iteration += 1;
}
(coef_lin, coef_ang)
Expand Down
2 changes: 1 addition & 1 deletion lurk-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ thread_local! {
/// allows us not to think about contention on a global metrics sink among threads.
///
/// A global metrics sink must be installed before any thread-local sinks can be accessed.
static LOCAL_SINK: OnceCell<ThreadMetricsSinkHandle> = OnceCell::new();
static LOCAL_SINK: OnceCell<ThreadMetricsSinkHandle> = const { OnceCell::new() };
}

/// A global metrics sink that keeps a list of thread-local sinks to aggregate from
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[toolchain]
# The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy.
profile = "default"
channel = "1.76"
channel = "1.78"
targets = [ "wasm32-unknown-unknown" ]

1 change: 1 addition & 0 deletions src/circuit/gadgets/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt::Debug;

/// Initialized map entry for a fixed `key` with
/// an allocated `value` computed at runtime.
#[allow(dead_code)]
pub(crate) struct CaseClause<'a, F: LurkField> {
pub(crate) key: F,
pub(crate) value: &'a AllocatedNum<F>,
Expand Down
4 changes: 2 additions & 2 deletions src/lem/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn build_frames<F: LurkField, C: Coprocessor<F>>(
compute_frame(lurk_step, cprocs, &input, store, lang, ch_terminal, pc)?;

iterations += 1;
input = frame.output.clone();
input.clone_from(&frame.output);
tracing::info!("{}", &log_fmt(iterations, &input, store));
let expr = frame.output[0];
frames.push(frame);
Expand Down Expand Up @@ -139,7 +139,7 @@ fn traverse_frames<F: LurkField, C: Coprocessor<F>>(
compute_frame(lurk_step, cprocs, &input, store, lang, ch_terminal, pc)?;

iterations += 1;
input = frame.output.clone();
input.clone_from(&frame.output);

if must_break {
break;
Expand Down
1 change: 1 addition & 0 deletions src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl From<Op1> for u64 {
}
}

#[allow(dead_code)]
pub(crate) trait Op
where
Self: 'static,
Expand Down
36 changes: 18 additions & 18 deletions src/z_data/serde/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,26 @@ impl<'a> ser::Serializer for &'a Serializer {
}

#[inline]
fn serialize_newtype_struct<T: ?Sized>(
fn serialize_newtype_struct<T>(
self,
_name: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
value.serialize(self)
}

fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
// Assuming # of variants < 256
Ok(ZData::Cell(vec![
Expand All @@ -205,9 +205,9 @@ impl<'a> ser::Serializer for &'a Serializer {
}

#[inline]
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
Ok(ZData::Cell(vec![value.serialize(self)?]))
}
Expand Down Expand Up @@ -292,9 +292,9 @@ impl ser::SerializeSeq for SerializeCell {
type Ok = ZData;
type Error = SerdeError;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
self.cell.push(value.serialize(&Serializer)?);
Ok(())
Expand All @@ -309,9 +309,9 @@ impl ser::SerializeTuple for SerializeCell {
type Ok = ZData;
type Error = SerdeError;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
ser::SerializeSeq::serialize_element(self, value)
}
Expand All @@ -325,9 +325,9 @@ impl ser::SerializeTupleStruct for SerializeCell {
type Ok = ZData;
type Error = SerdeError;

fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
ser::SerializeSeq::serialize_element(self, value)
}
Expand All @@ -341,9 +341,9 @@ impl ser::SerializeTupleVariant for SerializeTupleVariant {
type Ok = ZData;
type Error = SerdeError;

fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
self.cell.push(value.serialize(&Serializer)?);
Ok(())
Expand All @@ -362,17 +362,17 @@ impl ser::SerializeMap for SerializeMap {
type Ok = ZData;
type Error = SerdeError;

fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
self.next_key = Some(key.serialize(&Serializer)?);
Ok(())
}

fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ser::Serialize,
T: ?Sized + ser::Serialize,
{
let key = self
.next_key
Expand Down

1 comment on commit 7febc96

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
32 vCPUs
125 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/9331538473

Benchmark Results

LEM Fibonacci Prove - rc = 100

ref=76573535bef95ffcdf095a932a245baf2940e4a5 ref=7febc969474624e6cae8810a0c1e402da70ba2c6
num-100 1.51 s (✅ 1.00x) 1.48 s (✅ 1.02x faster)
num-200 2.85 s (✅ 1.00x) 2.84 s (✅ 1.00x faster)

LEM Fibonacci Prove - rc = 600

ref=76573535bef95ffcdf095a932a245baf2940e4a5 ref=7febc969474624e6cae8810a0c1e402da70ba2c6
num-100 1.88 s (✅ 1.00x) 1.87 s (✅ 1.00x faster)
num-200 3.09 s (✅ 1.00x) 3.06 s (✅ 1.01x faster)

Made with criterion-table

Please sign in to comment.