Live data from Hacker News

ProjectPSX – A C# coded emulator of the original Playstation

github.com

41–50 of 62 posts

Re: ProjectPSX – A C# coded emulator of the original Playstation

#41
post #7

As a day-to-day C# developer, I'm curious about a few things: - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? (Apologies that I didn't read the source code.)

Hello There, I'm the owner of this repo. So nice that has ended here somehow. Gonna answer the upper quests... - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? The GC dosn't cause noticeable pausing on my setup. Even tho it could allocate less. - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? In fact it was done without unsafe code…

[deleted]

Re: ProjectPSX – A C# coded emulator of the original Playstation

#42
post #7

As a day-to-day C# developer, I'm curious about a few things: - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? (Apologies that I didn't read the source code.)

I haven't read the code, but you usually don't let the garbage collector get a chance to do anything with projects where it matters.

Typically, you choose where to optimize after collecting metrics.

The .Net garbage collector is a highly optimized generational garbage collector. Practices like pre-allocating and pooling are discouraged, because most of the time they are premature optimization.

In general, the best way to think about it is to pretend that the garbage collector is a built-in library for pooling and reusing objects.

If, early in your project's lifecycle, you suspect that you'll need to implement your own object pool, just start with stub "Get/Recycle" methods that call new / no-op. You can always swap in a pool later.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#43
post #7

As a day-to-day C# developer, I'm curious about a few things: - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? (Apologies that I didn't read the source code.)

Hello There, I'm the owner of this repo. So nice that has ended here somehow. Gonna answer the upper quests... - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? The GC dosn't cause noticeable pausing on my setup. Even tho it could allocate less. - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? In fact it was done without unsafe code…

Incredible work, congrats!

Re: ProjectPSX – A C# coded emulator of the original Playstation

#44
This is great! I've often wondered how emulators are actually written - I understand the theory but it was great to see this, and the linked other emulators this person has also worked on (chip8, gameboy etc).

Super nice and simple to read - e.g. cpu.cs has the thing that does the actual "MUL" and "MOV" etc op codes. Nice :-)

Thanks :-)

Re: ProjectPSX – A C# coded emulator of the original Playstation

#45
post #36

Earlier quoted context omitted.

They made a survey but that doesn’t mean they will listen to the feedback.

Windows Forms, WPF, C++/CLI, EF 6, .NET Native, WinUI kind of prove that they do, even if it takes a while to actually pay attention. Even in regards to WCF, I am not sure if they won't be forced to provide some gRPC migration path, when some Fortune 500 start to complain rather loudly.

> when some Fortune 500 start to complain rather loudly

Not sure it’s such a huge deal, .NET core already has the most complex parts of the WCF. It has fast async TCP and named pipe streams. It has .NET binary XML support, DataContractSerializer, XmlDictionaryReader, XmlDictionaryWriter classes, technically IMO better than protocol buffers: no foreign languages, similar level of performance, convertable to/from text XML if you want a human readable format for easier debugging.

When I needed RPC server in a Linux app written in .NET core, I wrote my own WCF-like thing. I’ve made a T4 template which generates requests/response & envelope classes, and channel factories, using compile-time reflection (EnvDTE stuff) of my service contracts. Took me a few hours. These Fortune 500 companies can probably afford doing the same when they need RPC in .NET.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#46
post #32

Earlier quoted context omitted.

I skimmed the code a little and did a few Github searches on it and it looks like the only unsafe blocks of code are in the core data bus. It's not entirely clear why it was done that way, as the CPU itself is using managed arrays to represent memory. Perhaps it was necessary for speed, as it seems primarily concerned with loading the executables that are to be emulated. Otherwise, everything looks statically allocat…

A rather useful pattern in C# is to load a blob into a byte array, then inside unsafe code, typecast it to a pointer to well-defined struct. There's also managed ways to do that, but they are slower and involve copying memory.

Any chance you have an example of this pattern you can point to? Also, would the use of Span make it possible to do this without unsafe code?

Re: ProjectPSX – A C# coded emulator of the original Playstation

#47
post #4

> ProjectPSX dosn't use any external dependency and uses rather simplistic C# code. Very impressive. This makes it more interesting to see how the drawing code and the controls were implemented in addition to the possibility of it being cross-platform if it using .NET Core.

It uses System.Windows.Forms and friends. It is a Windows app.

It has like 50 lines of code that are actually platform dependent, from what I can see.

Should be straightforward to port to GTK# or Eto.Forms or something, if one had the inclination.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#48
post #3

And one in Java: https://github.com/kilograham/jpsx

This one is fascinating - especially the slides from the JavaOne presentation. It JITs heavily-used R3000 blocks into Java bytecode, which is then JITted by the Java interpreter. And he did it 14 years ago!

Re: ProjectPSX – A C# coded emulator of the original Playstation

#49
post #36

Earlier quoted context omitted.

Windows Forms, WPF, C++/CLI, EF 6, .NET Native, WinUI kind of prove that they do, even if it takes a while to actually pay attention. Even in regards to WCF, I am not sure if they won't be forced to provide some gRPC migration path, when some Fortune 500 start to complain rather loudly.

> when some Fortune 500 start to complain rather loudly Not sure it’s such a huge deal, .NET core already has the most complex parts of the WCF. It has fast async TCP and named pipe streams. It has .NET binary XML support, DataContractSerializer, XmlDictionaryReader, XmlDictionaryWriter classes, technically IMO better than protocol buffers: no foreign languages, similar level of performance, convertable to/from text…

Nope, usually IT is a cost center, it isn't the main business of the Fortune 500 and if it works, has been battle tested in production, there are zero reasons to rewrite it, just because someone is feeling modern without offering a painless migration path.

Re: ProjectPSX – A C# coded emulator of the original Playstation

#50
post #24
post #7

As a day-to-day C# developer, I'm curious about a few things: - Do you ever find that the Garbage Collector causes noticeable pausing in the emulator? - Did you do this with 100% managed memory, or do you need to use unsafe code / real pointers? (Apologies that I didn't read the source code.)

Search the repo for "new" and you'll see that everything is allocated at construction time. Everything hangs off the window class so essentially all memory is allocated as the project starts up. You'd probably want to pre-allocate in any language because but this also relieves GC pressure. Another thing you can do in C# is leverage stack allocation using structs.

Relatedly, the new .NET Span APIs open up a lot more opportunities for stack allocation and "pointer arithmetic-style" work in "safe" code. Span is really fascinating at the performance opportunities it opens in .NET (and real performance gains already achieved in, for instance, ASP.NET Core).
Post reply on HN