MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / allocation_debt

Method allocation_debt

aiscript-arena/src/metrics.rs:141–174  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

139 /// faster than that of allocation so that collection will always complete.
140 #[inline]
141 pub fn allocation_debt(&self) -> f64 {
142 let total_gcs = self.0.total_gcs.get();
143 if total_gcs == 0 {
144 // If we have no live `Gc`s, then there is no possible collection to do so always
145 // return zero debt.
146 return 0.0;
147 }
148
149 // Every allocation in a cycle is a debit.
150 let raw_cycle_debits =
151 self.0.allocated_gc_bytes.get() as f64 + self.0.allocated_external_bytes.get() as f64;
152
153 // We do not begin collection at all until the allocations in a cycle reach the wakeup
154 // amount.
155 let cycle_debits = raw_cycle_debits - self.0.wakeup_amount.get();
156 if cycle_debits <= 0.0 {
157 return 0.0;
158 }
159
160 // Estimate the amount of external memory that has been traced assuming that each Gc
161 // owns an even share of the external memory.
162 let traced_external_estimate = self.0.traced_gcs.get() as f64 / total_gcs as f64
163 * self.0.total_external_bytes.get() as f64;
164
165 // Tracing or freeing memory counts as a credit.
166 let cycle_credits = self.0.traced_gc_bytes.get() as f64
167 + self.0.freed_gc_bytes.get() as f64
168 + traced_external_estimate
169 + self.0.freed_external_bytes.get() as f64;
170
171 let debt = cycle_debits * self.0.pacing.get().debit_factor - cycle_credits;
172
173 debt.max(0.0)
174 }
175
176 /// Call to mark that bytes have been externally allocated that are owned by an arena.
177 ///

Callers 2

do_collection_innerMethod · 0.80
interpretMethod · 0.80

Calls 1

getMethod · 0.45

Tested by

no test coverage detected