mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	 dff70b50d0
			
		
	
	
		dff70b50d0
		
	
	
	
	
		
			
			the original rb_wasm_setjmp implementation always unwinds to the root
call frame to have setjmp compatible interface, and simulate sjlj's
undefined behavior. Therefore, every vm_exec call unwinds to main, and
a deep call stack makes setjmp call very expensive. The following
snippet from optcarrot takes 5s even though it takes less than 0.3s on
native.
```
[0x0, 0x4, 0x8, 0xc].map do |attr|
  (0..7).map do |j|
    (0...0x10000).map do |i|
      clr = i[15 - j] * 2 + i[7 - j]
      clr != 0 ? attr | clr : 0
    end
  end
end
```
This patch adds a WASI specialized vm_exec which uses lightweight
try-catch API without unwinding to the root frame. After this patch, the
above snippet takes only 0.5s.
		
	
			
		
			
				
	
	
		
			23 lines
		
	
	
	
		
			881 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
	
		
			881 B
		
	
	
	
		
			C
		
	
	
	
	
	
| #ifndef RB_WASM_SUPPORT_ASYNCIFY_H
 | |
| #define RB_WASM_SUPPORT_ASYNCIFY_H
 | |
| 
 | |
| __attribute__((import_module("asyncify"), import_name("start_unwind")))
 | |
| void asyncify_start_unwind(void *buf);
 | |
| #define asyncify_start_unwind(buf) do {  \
 | |
|     extern void *rb_asyncify_unwind_buf; \
 | |
|     rb_asyncify_unwind_buf = (buf);      \
 | |
|     asyncify_start_unwind((buf));        \
 | |
|   } while (0)
 | |
| __attribute__((import_module("asyncify"), import_name("stop_unwind")))
 | |
| void asyncify_stop_unwind(void);
 | |
| #define asyncify_stop_unwind() do {      \
 | |
|     extern void *rb_asyncify_unwind_buf; \
 | |
|     rb_asyncify_unwind_buf = NULL;       \
 | |
|     asyncify_stop_unwind();              \
 | |
|   } while (0)
 | |
| __attribute__((import_module("asyncify"), import_name("start_rewind")))
 | |
| void asyncify_start_rewind(void *buf);
 | |
| __attribute__((import_module("asyncify"), import_name("stop_rewind")))
 | |
| void asyncify_stop_rewind(void);
 | |
| 
 | |
| #endif
 |