-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Avoid storage caching in benchmarks #1469
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,6 +633,7 @@ fn linear_regression(x_y: Vec<(u64, u64)>) -> f64 { | |
fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the types are getting confusing you could even set the type as |
||
const NEAR_LINEAR: f64 = 0.1; | ||
|
||
#[derive(PartialEq, Eq)] | ||
enum Type { | ||
/// The points have a linear property. The first point | ||
/// and the last points are almost the same(The difference is < 0.1). | ||
|
@@ -671,7 +672,7 @@ fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { | |
|
||
let linear_regression = linear_regression(x_y.clone()); | ||
|
||
let mut x_y = x_y | ||
let x_y = x_y | ||
.into_iter() | ||
.map(|(x, y)| Point { x, y }) | ||
.collect::<Vec<_>>(); | ||
|
@@ -704,7 +705,15 @@ fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { | |
.unwrap(); | ||
(base, amount as u64) | ||
} | ||
Type::Logarithm => { | ||
Type::Logarithm | Type::Exp => { | ||
if expected_type == Type::Exp { | ||
println!( | ||
"The {} is exponential. We don't support exponential chart. \ | ||
The opcode should be limited with upper bound. \n {:?}", | ||
name, x_y | ||
); | ||
} | ||
|
||
// The logarithm function slows down fast, and the point where it becomes more | ||
// linear is the base point. After this point we use linear strategy. | ||
let last = x_y.last().unwrap().amount(); | ||
|
@@ -726,17 +735,6 @@ fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { | |
.unwrap_or(last); | ||
(base.y, amount as u64) | ||
} | ||
Type::Exp => { | ||
println!( | ||
"The {} is exponential. We don't support exponential chart. \ | ||
The opcode should be limited with upper bound. \n {:?}", | ||
name, x_y | ||
); | ||
|
||
x_y.sort_unstable_by_key(|a| a.amount() as u64); | ||
let base = x_y.last().unwrap(); | ||
(base.y, 0) | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
use crate::database::{ | ||
Column, | ||
Database, | ||
Error as DatabaseError, | ||
Result as DatabaseResult, | ||
}; | ||
use fuel_core_storage::iter::{ | ||
|
@@ -87,6 +89,12 @@ pub enum WriteOperation { | |
} | ||
|
||
pub trait TransactableStorage: BatchOperations + Debug + Send + Sync { | ||
fn checkpoint(&self) -> DatabaseResult<Database> { | ||
Err(DatabaseError::Other(anyhow::anyhow!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to add an error variant for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on the situation, in the case of checkpoints it's only used in benchmarking / test contexts and we don't do any special logic based on the error variant other than bailing from the benchmark. https://www.lpalmieri.com/posts/error-handling-rust/#anyhow-or-thiserror |
||
"Checkpoint is not supported" | ||
))) | ||
} | ||
|
||
fn flush(&self) -> DatabaseResult<()>; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really representative of real world conditions though? Since we'll pretty much always be executing this opcode from within a db transaction when going through the block executor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to avoid optimizations from
MemoryTransactionView
in the case of non-first interaction with the storage key. Using checkpoint instead ofMemoryTransactionView
, we go toself.data_source.get(key, column)
branch directly.But yeah, it is not real-world execution. Because inside of the block, we have
RocksDB -> MemoryTransactionView -> MemoryTransactionView
. We can create a specialBenchmarkMemoryTransactionView
for benchmarks that does all the same thing, except it always goes todata_source
. But I think the overhead fromMemoryTransactionView
is much lesser than direct access to the checkpoint database. The proof is a significant increase in the execution time of the opcode for case with1
.