Skip to content

Commit f23eb15

Browse files
Revert "Properly handle execution time<->energy conversion in v8 host (#4884)" (#4927)
# Description of Changes <!-- Please describe your change, mention any related tickets, and so on here. --> This reverts commit 458eac8. This rolls back a pricing change that we made to V8 (TypeScript) based modules. This will be applied as a hotfix to 2.2.0. # API and ABI breaking changes <!-- If this is an API or ABI breaking change, please apply the corresponding GitHub label. --> None # Expected complexity level and risk 1 - Just a pricing change. <!-- How complicated do you think these changes are? Grade on a scale from 1 to 5, where 1 is a trivial change, and 5 is a deep-reaching and complex change. This complexity rating applies not only to the complexity apparent in the diff, but also to its interactions with existing and future code. If you answered more than a 2, explain what is complex about the PR, and what other components it interacts with in potentially concerning ways. --> # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] Tested on staging - I didn't verify that the energy used went down because I don't think I can do that on staging but at least I know this doesn't appear to break anything. Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
1 parent 6e4b83a commit f23eb15

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

crates/client-api-messages/src/energy.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ pub struct EnergyQuanta {
1616
impl EnergyQuanta {
1717
pub const ZERO: Self = EnergyQuanta { quanta: 0 };
1818

19-
// per the comment on [`FunctionBudget::DEFAULT_BUDGET`]: 1 second of wasm runtime is roughtly 2 TeV
20-
pub const PER_EXECUTION_SEC: Self = Self::new(2_000_000_000_000);
21-
pub const PER_EXECUTION_NANOSEC: Self = Self::new(Self::PER_EXECUTION_SEC.get() / 1_000_000_000);
22-
2319
#[inline]
24-
pub const fn new(quanta: u128) -> Self {
20+
pub fn new(quanta: u128) -> Self {
2521
Self { quanta }
2622
}
2723

2824
#[inline]
29-
pub const fn get(&self) -> u128 {
25+
pub fn get(&self) -> u128 {
3026
self.quanta
3127
}
3228

crates/core/src/host/v8/budget.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::ptr;
1313
use core::sync::atomic::Ordering;
1414
use core::time::Duration;
1515
use core::{ffi::c_void, sync::atomic::AtomicBool};
16-
use spacetimedb_client_api_messages::energy::{EnergyQuanta, FunctionBudget};
16+
use spacetimedb_client_api_messages::energy::FunctionBudget;
1717
use std::sync::Arc;
1818
use v8::{Isolate, IsolateHandle};
1919

@@ -118,12 +118,7 @@ fn budget_to_duration(_budget: FunctionBudget) -> Duration {
118118
/// Returns [`EnergyStats`] for a reducer given its `budget`
119119
/// and the `duration` it took to execute.
120120
pub(super) fn energy_from_elapsed(budget: FunctionBudget, duration: Duration) -> EnergyStats {
121-
let used = duration.as_nanos() * EnergyQuanta::PER_EXECUTION_NANOSEC.get();
122-
// in order for duration_nanos * ev_per_ns >= u64::MAX:
123-
// duration_nanos >= u64::MAX / ev_per_ns
124-
// duration_nanos >= (9223372036854775 ns = 106.75 days)
125-
// so it's unlikely we'll have to worry about it
126-
let used = FunctionBudget::new(u64::try_from(used).unwrap_or(u64::MAX));
121+
let used = duration_to_budget(duration);
127122
let remaining = budget - used;
128123
EnergyStats { budget, remaining }
129124
}

0 commit comments

Comments
 (0)