Skip to content

Commit 1e44839

Browse files
committed
Use Thread.pass within TracePoint hook to improve REPL responce
Loading RBS could be heavy. It will frequently block main thread of IRB especially when IRB is loading RDoc. Use TracePoint :call hook to pass thread execution while loading RBS will reduce main thread blocking.
1 parent cbb2cfb commit 1e44839

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

lib/repl_type_completor/types.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ def self.load_rbs_builder
3838
end
3939
end
4040

41-
env = RBS::Environment.from_loader(loader)
42-
# [Hack] Monkey patch for improving development experience
43-
def env.resolve_declaration(*, **)
44-
Thread.pass
45-
super
41+
# Hack to make this thread priority lower, not to block the main thread.
42+
thread_pass_counter = 0
43+
tracepoint = TracePoint.new(:call) do
44+
Thread.pass if ((thread_pass_counter += 1) % 10).zero?
45+
end
46+
tracepoint.enable do
47+
env = RBS::Environment.from_loader(loader)
48+
@rbs_builder = RBS::DefinitionBuilder.new env: env.resolve_type_names
4649
end
47-
@rbs_builder = RBS::DefinitionBuilder.new env: env.resolve_type_names
4850
rescue LoadError, StandardError => e
4951
@rbs_load_error = e
5052
nil

0 commit comments

Comments
 (0)