Skip to content

Commit 46ea21e

Browse files
committed
ZJIT: Remove from Invariants on invalidation
Previously, we kept around `PatchPoint`s after patching them for several kinds of invariants. That wasted compute since repeated invalidation with the same key patched a growing list of patchpoints each time, making it accidentally O(n^2). Retaining the patchpoints also used memory. Some invariants, such as rb_zjit_invalidate_no_singleton_class() and rb_zjit_invalidate_root_box(), already remove from the table. This commit makes all invariants remove from the table.
1 parent b6e4fa7 commit 46ea21e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

zjit/src/invariants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub extern "C" fn rb_zjit_bop_redefined(klass: RedefinitionFlag, bop: ruby_basic
188188

189189
with_vm_lock(src_loc!(), || {
190190
let invariants = ZJITState::get_invariants();
191-
if let Some(patch_points) = invariants.bop_patch_points.get(&(klass, bop)) {
191+
if let Some(patch_points) = invariants.bop_patch_points.remove(&(klass, bop)) {
192192
let cb = ZJITState::get_code_block();
193193
let bop = Invariant::BOPRedefined { klass, bop };
194194
debug!("BOP is redefined: {}", bop);
@@ -372,7 +372,7 @@ pub extern "C" fn rb_zjit_constant_state_changed(id: ID) {
372372

373373
with_vm_lock(src_loc!(), || {
374374
let invariants = ZJITState::get_invariants();
375-
if let Some(patch_points) = invariants.constant_state_patch_points.get(&id) {
375+
if let Some(patch_points) = invariants.constant_state_patch_points.remove(&id) {
376376
let cb = ZJITState::get_code_block();
377377
debug!("Constant state changed: {:?}", id);
378378

0 commit comments

Comments
 (0)