Skip to content

Conversation

@byroot
Copy link
Contributor

@byroot byroot commented Feb 9, 2025

Precomputing one Proc per possible address amount of 8MiB of memory and almost 100k objects the GC as to scan etc.

This can be reduced to just 24 objects with only an extra bitshift on access.

Precomputing one Proc per possible address amount of 8MiB of memory
and almost 100k objects the GC as to scan etc.

This can be reduced to just 24 objects with only an extra
bitshit on access.
byroot added a commit to byroot/rubyboy that referenced this pull request Feb 9, 2025
Closes: sacckey#23

Having to call a proc for every memory access isn't ideal, that
quite a bit of overhead.

If instead we use a `case` statement with only immediate values
and a few bitwise operations we can let YJIT generate very efficient
code.

two runs on main with ruby 3.4.1 / YJIT:

```
Ruby: 3.4.1
YJIT: true
1: 4.051815 sec
2: 3.989457 sec
3: 3.963555 sec
FPS: 374.849216902501

Ruby: 3.4.1
YJIT: true
1: 3.872855 sec
2: 3.943231 sec
3: 4.024268 sec
FPS: 380.05620440064547
```

On this branch:

```
Ruby: 3.4.1
YJIT: true
1: 3.625805 sec
2: 3.615032 sec
3: 3.572852 sec
FPS: 416.1392102177157

Ruby: 3.4.1
YJIT: true
1: 3.543953 sec
2: 3.520738 sec
3: 3.506004 sec
FPS: 425.70521616601366
```
@byroot byroot mentioned this pull request Feb 9, 2025
@byroot
Copy link
Contributor Author

byroot commented Feb 9, 2025

Actually there's much simpler: #24

@byroot byroot closed this Feb 10, 2025
byroot added a commit to byroot/rubyboy that referenced this pull request Feb 10, 2025
Closes: sacckey#23

Having to call a proc for every memory access isn't ideal, that
quite a bit of overhead.

If instead we use a `case` statement with only immediate values
and a few bitwise operations we can let YJIT generate very efficient
code.

two runs on main with ruby 3.4.1 / YJIT:

```
Ruby: 3.4.1
YJIT: true
1: 4.051815 sec
2: 3.989457 sec
3: 3.963555 sec
FPS: 374.849216902501

Ruby: 3.4.1
YJIT: true
1: 3.872855 sec
2: 3.943231 sec
3: 4.024268 sec
FPS: 380.05620440064547
```

On this branch:

```
Ruby: 3.4.1
YJIT: true
1: 3.625805 sec
2: 3.615032 sec
3: 3.572852 sec
FPS: 416.1392102177157

Ruby: 3.4.1
YJIT: true
1: 3.543953 sec
2: 3.520738 sec
3: 3.506004 sec
FPS: 425.70521616601366
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant