ITotalJustice / notorious_beeg

gba emulator written in c++23
https://notorious-beeg.netlify.app/
GNU General Public License v3.0
41 stars 4 forks source link

std::span might be a performance hit #14

Closed ITotalJustice closed 2 years ago

ITotalJustice commented 2 years ago

std::span is a container that's 16-bytes (ptr + std::size_t).

currently, it is used for all reads / writes here https://github.com/ITotalJustice/notorious_beeg/blob/33dd365225600be9ed4d5ff45d9380f4dad25b48/src/core/mem.hpp#L259 https://github.com/ITotalJustice/notorious_beeg/blob/33dd365225600be9ed4d5ff45d9380f4dad25b48/src/core/mem.hpp#L274

now, the size is not needed for these functions, so passing a struct around is very uneeded. this of course does not matter when the function is inlined, which it is (in release mode). However, i am not so sure about its effects with msvc.

the emulator performance with msvc is shocking. a game which achieves 1.3k fps on linux (both gcc and clang) only reaches 600 fps with msvc. with clang-cl (windows) performance is 1k fps, which is about what i expected.

there are numerous posts online about the performance hit of std::span with msvc, however they state that it wont be an issue if the function is inlined, which i assume it is.

NOTE: i tested using std::array instead of C-arrays for my memory struct. on linux, i did notice a very small performance hit. i am not sure if this is due to the constructor of std::span happening on every r/w, or it's within margin of error. i don't think there should be any hit at all. from 1300 to ~1250.

ITotalJustice commented 2 years ago

there's a separate branch for this now, going to be used to benchmark across compilers

https://github.com/ITotalJustice/notorious_beeg/commits/spanless-mem

ITotalJustice commented 2 years ago

i already merged that branch in https://github.com/ITotalJustice/notorious_beeg/commit/b16858a630002d1790ccf73d2e8af01137623984.

closing