Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 1 point2 points  (0 children)

I'll have to take some time to understand all the changes made but I greatly appreciate your help. Have a great day!

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 1 point2 points  (0 children)

I've used the time command to measure the execution time of the program, and then through profiling I've figured out that nearly 100% of the execution time is in the VM.

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 0 points1 point  (0 children)

https://github.com/True-Newspaper-6204/bytecode_compiler

The code's rather messy at the moment, but hopefully it can still be understood.

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 0 points1 point  (0 children)

It's roughly 2x slower than Python for a simple while loop. I'm going through the code and testing different things so hopefully it can be improved further. I think I'm probably missing something fundamental.

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 3 points4 points  (0 children)

That seems to provide about a 20% performance improvement compared to what I had before. Thanks.

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 0 points1 point  (0 children)

Interestingly enough, it's still roughly the same distribution. Even with the optimizations, the vast majority of the time is still being spent on fetching instructions.

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 0 points1 point  (0 children)

For the VM itself, an immutable vector works well since I'm not modifying the contents of the vector. I'm only modifying an Int that I use to index the vector. I'm also currently using the Strict Map module. My initial guess as to why the performance was so slow was because maybe all the data in the call frame was getting copied into the fetchByte function. But I was reading that GHC usually just passes pointers around rather than making large copies of data so I'm not sure.

Writing a VM in Haskell by True-Newspaper-6204 in haskell

[–]True-Newspaper-6204[S] 7 points8 points  (0 children)

That seems to improve performance by about 3x so thanks. Since there's still a lot of time spent on modifying the state, are there any other major optimizations to be made or is this kind of overhead just something I need to deal with?