[前][次][番号順一覧][スレッド一覧]

ruby-changes:71487

From: Yusuke <ko1@a...>
Date: Thu, 24 Mar 2022 09:47:43 +0900 (JST)
Subject: [ruby-changes:71487] 9112cf4ae7 (master): regint.h: Reduce the frequency of rb_thread_check_ints

https://git.ruby-lang.org/ruby.git/commit/?id=9112cf4ae7

From 9112cf4ae7f7ea8ab33c282aa02eec812421aeab Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Thu, 24 Mar 2022 01:57:34 +0900
Subject: regint.h: Reduce the frequency of rb_thread_check_ints

edc8576a65b7082597d45a694434261ec3ac0d9e checks interrupt at every
backtrack, which brought significant overhead.

This change makes the check only once every 128 backtracks.
---
 regexec.c | 2 ++
 regint.h  | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/regexec.c b/regexec.c
index f6435d84c6..9535e45228 100644
--- a/regexec.c
+++ b/regexec.c
@@ -421,6 +421,7 @@ onig_region_copy(OnigRegion* to, const OnigRegion* from) https://github.com/ruby/ruby/blob/trunk/regexec.c#L421
   (msa).start    = (arg_start);\
   (msa).gpos     = (arg_gpos);\
   (msa).best_len = ONIG_MISMATCH;\
+  (msa).counter  = 0;\
 } while(0)
 #else
 # define MATCH_ARG_INIT(msa, arg_option, arg_region, arg_start, arg_gpos) do {\
@@ -429,6 +430,7 @@ onig_region_copy(OnigRegion* to, const OnigRegion* from) https://github.com/ruby/ruby/blob/trunk/regexec.c#L430
   (msa).region   = (arg_region);\
   (msa).start    = (arg_start);\
   (msa).gpos     = (arg_gpos);\
+  (msa).counter  = 0;\
 } while(0)
 #endif
 
diff --git a/regint.h b/regint.h
index b136d804dc..0e9777cc1e 100644
--- a/regint.h
+++ b/regint.h
@@ -148,7 +148,13 @@ https://github.com/ruby/ruby/blob/trunk/regint.h#L148
 
 #ifdef RUBY
 
-# define CHECK_INTERRUPT_IN_MATCH_AT rb_thread_check_ints()
+# define CHECK_INTERRUPT_IN_MATCH_AT do { \
+  msa->counter++;                         \
+  if (msa->counter >= 128) {              \
+    msa->counter = 0;                     \
+    rb_thread_check_ints();               \
+  }                                       \
+} while(0)
 # define onig_st_init_table                  st_init_table
 # define onig_st_init_table_with_size        st_init_table_with_size
 # define onig_st_init_numtable               st_init_numtable
@@ -870,6 +876,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/regint.h#L876
   void* state_check_buff;
   int   state_check_buff_size;
 #endif
+  int counter;
 } OnigMatchArg;
 
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]