Skip to content

Commit

Permalink
RJIT: Avoid retaining comments unless --rjit-dump-disasm
Browse files Browse the repository at this point in the history
This significantly reduces retained objects on RJIT.
  • Loading branch information
k0kubun committed Dec 19, 2023
1 parent 8671cd5 commit 8d5af35
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/ruby_vm/rjit/code_block.rb
Expand Up @@ -4,7 +4,7 @@ class CodeBlock
# @param mem_size [Integer] JIT buffer size
# @param outliend [TrueClass,FalseClass] true for outlined CodeBlock
def initialize(mem_block:, mem_size:, outlined: false)
@comments = Hash.new { |h, k| h[k] = [] }
@comments = Hash.new { |h, k| h[k] = [] } if dump_disasm?
@mem_block = mem_block
@mem_size = mem_size
@write_pos = 0
Expand All @@ -26,7 +26,7 @@ def write(asm)

# Convert comment indexes to addresses
asm.comments.each do |index, comments|
@comments[start_addr + index] += comments
@comments[start_addr + index] += comments if dump_disasm?
end
asm.comments.clear

Expand All @@ -39,7 +39,7 @@ def write(asm)

def set_write_addr(addr)
@write_pos = addr - @mem_block
@comments.delete(addr) # TODO: clean up old comments for all the overwritten range?
@comments.delete(addr) if dump_disasm?
end

def with_write_addr(addr)
Expand Down Expand Up @@ -83,5 +83,9 @@ def colorize(text, bold: false, color:)
def bold(text)
"\e[1m#{text}\e[0m"
end

def dump_disasm?
C.rjit_opts.dump_disasm
end
end
end

0 comments on commit 8d5af35

Please sign in to comment.