Skip to content

Stop conflating EnergyQuanta and FunctionBudget#4930

Open
coolreader18 wants to merge 2 commits intomasterfrom
noa/unconflate-budget-and-energy
Open

Stop conflating EnergyQuanta and FunctionBudget#4930
coolreader18 wants to merge 2 commits intomasterfrom
noa/unconflate-budget-and-energy

Conversation

@coolreader18
Copy link
Copy Markdown
Collaborator

Description of Changes

A sort of followup to #4884, an alternative to #4927.

In #3832, we made FunctionBudget a different unit than EnergyQuanta, but there were still many places where we treated them the same and directly converted between them. I got confused by that in #4884, and now this PR properly separates them and corrects the v8 energy calculation.

Expected complexity level and risk

3 - touches energy calculation without reverting the problematic #4884, but I'm confident it's correct this time.

Testing

  • Verified that the conversion factors make sense for wasmtime and for v8.

@coolreader18 coolreader18 requested a review from cloutiertyler May 1, 2026 19:25
// elsewhere. So, we just pretend that this is `EnergyQuanta` when it's actually
// a different unit, and it doesn't really matter to the client anyway.
// TODO(noa): maybe we could just have this be zero, unconditionally?
energy_quanta_used: EnergyQuanta::new(event.execution_energy_used.get().into()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could take this opportunity to rename energy_quanta_used to avoid accidental errors in the future. That seems like it might be worth it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the ws_v1 client api struct.

pub status: EventStatus,
pub reducer_return_value: Option<Bytes>,
pub energy_quanta_used: EnergyQuanta,
pub execution_energy_used: FunctionBudget,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would also not call this energy if it's not energy. CPU instruction estimate seems more apt.

Copy link
Copy Markdown
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

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

Left some comments.

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