Commit 8afd975
committed
compile.c: deduplicate inline constant caches
If a method reference the same constant twice or more, it can
use a single constant cache for all the instructions.
```ruby
puts RubyVM::InstructionSequence.compile(<<~RUBY).disasm
Foo::Bar + Foo::Bar + Bar + Bar
RUBY
```
Before
```
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,31)>
0000 opt_getconstant_path <ic:0 Foo::Bar> ( 1)[Li]
0002 opt_getconstant_path <ic:1 Foo::Bar>
0004 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0006 opt_getconstant_path <ic:2 Bar>
0008 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0010 opt_getconstant_path <ic:3 Bar>
0012 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0014 leave
```
After:
```
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,31)>
0000 opt_getconstant_path <ic:0 Foo::Bar> ( 1)[Li]
0002 opt_getconstant_path <ic:0 Foo::Bar>
0004 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0006 opt_getconstant_path <ic:1 Bar>
0008 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0010 opt_getconstant_path <ic:1 Bar>
0012 opt_plus <calldata!mid:+, argc:1, ARGS_SIMPLE>[CcCr]
0014 leave
```1 parent fab133e commit 8afd975
1 file changed
Lines changed: 50 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2518 | 2518 | | |
2519 | 2519 | | |
2520 | 2520 | | |
2521 | | - | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
2522 | 2527 | | |
2523 | 2528 | | |
2524 | 2529 | | |
| |||
2547 | 2552 | | |
2548 | 2553 | | |
2549 | 2554 | | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
2550 | 2582 | | |
2551 | 2583 | | |
2552 | 2584 | | |
| |||
2692 | 2724 | | |
2693 | 2725 | | |
2694 | 2726 | | |
2695 | | - | |
2696 | | - | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
2697 | 2736 | | |
2698 | 2737 | | |
2699 | 2738 | | |
2700 | 2739 | | |
2701 | 2740 | | |
2702 | 2741 | | |
2703 | 2742 | | |
2704 | | - | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
2705 | 2747 | | |
2706 | 2748 | | |
2707 | 2749 | | |
| |||
2828 | 2870 | | |
2829 | 2871 | | |
2830 | 2872 | | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
2831 | 2877 | | |
2832 | 2878 | | |
2833 | 2879 | | |
| |||
0 commit comments