Commit bd74da9
authored
perf: cache size and jump_target from first pass in to_bytecode (#200)
`ConcreteBytecode.to_bytecode` makes two passes over the instruction
list. The first pass (finding jump targets) already calls
`c_instr.get_jump_target(offset)` and `c_instr.size` for every
instruction. The main loop then called both again — redundantly, at the
same offsets.
This change stashes `(size, jump_target)` per instruction into a list
during the first pass and consumes it via an iterator in the main loop,
eliminating all second calls to `get_jump_target` and `size`.
| Hotspot | Before | After |
|---|---|---|
| `ConcreteBytecode.to_bytecode` own | 9.56% | 8.29% |
| `ConcreteBytecode.to_bytecode` total | 19.55% | 15.55% |
| `ConcreteInstr.get_jump_target` total | 2.74% | gone (< top 20) |
| `ConcreteInstr.size` total | 1.30% | gone (< top 20) |
| | Range | Avg |
|---|---|---|
| Before | 214–226 r/s | ~221 r/s |
| After | 224–232 r/s | ~229 r/s |
~3.5% throughput improvement.1 parent e5d1d74 commit bd74da9
1 file changed
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
785 | | - | |
| 785 | + | |
786 | 786 | | |
| 787 | + | |
787 | 788 | | |
788 | 789 | | |
789 | 790 | | |
790 | 791 | | |
| 792 | + | |
791 | 793 | | |
| 794 | + | |
792 | 795 | | |
793 | 796 | | |
794 | | - | |
| 797 | + | |
795 | 798 | | |
796 | 799 | | |
797 | 800 | | |
| |||
839 | 842 | | |
840 | 843 | | |
841 | 844 | | |
| 845 | + | |
842 | 846 | | |
843 | 847 | | |
844 | 848 | | |
| |||
864 | 868 | | |
865 | 869 | | |
866 | 870 | | |
867 | | - | |
868 | | - | |
| 871 | + | |
869 | 872 | | |
870 | 873 | | |
871 | 874 | | |
| |||
0 commit comments