flysim: read adapter.progress() once per publish
feed_game and feed_milestone each called adapter.progress() (a pure read), so every publish computed it twice. Both now take the snapshot as an argument; publish and the session service read it once. The header bytes are unchanged (service_parity and journal_replay pass).
This commit is contained in:
parent
1d29ab1ff8
commit
405cf11498
2 changed files with 9 additions and 4 deletions
|
|
@ -1272,9 +1272,10 @@ impl SessionHost {
|
|||
let macro_mode = self.shared.config.macros.mode;
|
||||
let semantic_rewards = self.semantic_rewards;
|
||||
let (game, milestone) = self.session.task.inspect(|adapter, ratchet, macros| {
|
||||
let progress = adapter.progress();
|
||||
(
|
||||
feed_game(adapter, semantic_rewards, macros, macro_mode, ms),
|
||||
feed_milestone(adapter, rank_since_ms, ms, ratchet.state.attempts),
|
||||
feed_game(adapter, &progress, semantic_rewards, macros, macro_mode, ms),
|
||||
feed_milestone(adapter, &progress, rank_since_ms, ms, ratchet.state.attempts),
|
||||
)
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1417,6 +1417,8 @@ impl Sim {
|
|||
let stats = self.agent.network.plasticity.statistics();
|
||||
let remaining = self.agent.network.reward_remaining();
|
||||
let cooldown = self.limiter.cooldown_ms(now_wall_ms());
|
||||
// One read of the adapter per publish: the header's `game` and `milestone` share it.
|
||||
let progress = self.adapter.progress();
|
||||
|
||||
let (frame, audio, spikes, spike_count, attachments) = if with_attachments {
|
||||
let (bitset, count) =
|
||||
|
|
@ -1458,6 +1460,7 @@ impl Sim {
|
|||
learning: feed_learning(&stats),
|
||||
game: feed_game(
|
||||
self.adapter.as_ref(),
|
||||
&progress,
|
||||
self.semantic_rewards,
|
||||
self.macros.as_ref(),
|
||||
self.shared.config.macros.mode,
|
||||
|
|
@ -1465,6 +1468,7 @@ impl Sim {
|
|||
),
|
||||
milestone: feed_milestone(
|
||||
self.adapter.as_ref(),
|
||||
&progress,
|
||||
self.rank_since_ms,
|
||||
ms,
|
||||
self.ratchet.state.attempts,
|
||||
|
|
@ -1600,12 +1604,12 @@ pub fn feed_learning(stats: &flybrain_core::plasticity::LearningStats) -> FeedLe
|
|||
/// The header's `game`: the adapter's progress and the macro layer's scene, palette and macro.
|
||||
pub fn feed_game(
|
||||
adapter: &dyn GameAdapter,
|
||||
progress: &ProgressSnapshot,
|
||||
semantic_rewards: bool,
|
||||
macros: Option<&MacroLayer>,
|
||||
macro_mode: MacroMode,
|
||||
ms: f64,
|
||||
) -> FeedGame {
|
||||
let progress = adapter.progress();
|
||||
let mut reward_counts = RewardCounts::default();
|
||||
for (kind, count) in &progress.counts {
|
||||
if let Some(kind) = RewardKind::from_adapter(kind) {
|
||||
|
|
@ -1640,11 +1644,11 @@ pub fn feed_game(
|
|||
/// §3). `rank_ladder()` is also what the page draws.
|
||||
pub fn feed_milestone(
|
||||
adapter: &dyn GameAdapter,
|
||||
progress: &ProgressSnapshot,
|
||||
rank_since_ms: f64,
|
||||
ms: f64,
|
||||
attempts: u64,
|
||||
) -> FeedMilestone {
|
||||
let progress = adapter.progress();
|
||||
let ladder = adapter.rank_ladder();
|
||||
// Which rung the fly is going for, when the adapter knows: see `next_label`.
|
||||
let next_rung = adapter.next_rung();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue