Live data from Hacker News

Porting my JavaScript game engine to C for no reason

phoboslab.org

131–139 of 139 posts

Re: Porting my JavaScript game engine to C for no reason

#131
post #125
post #121

I like the part about memory management. Arenas are so simple. In the (toy) web server I'm writing I initially also started with arenas. However I quickly realized that I don't actually need to grow and shrink memory at all. Currently I'm simply allocating the memory I need up front then slice it up into pieces for every module. When we're programming, we often pretend like we could be needing arbitrary amounts of me…

Right, I'm always annoyed when people talk about how std::vector has terrible performance (especially for games), which it certainly does if you just start with an empty vector with no memory reserved and append a few thousand items. But it is very frequently possible to find the actual maximum you will need, allocate that upfront, and everything's great.

Coincidentally that's how I started thinking about limits and allocating everything up front. I wanted to try out arena allocation, with one arena per http request (and one for the entire lifetime).

But when I realized that if I wouldn't allocate a large enough backing array (capacity) then memory would grow by n+(n+1)+(n+2)... every time I allocate on the arena during a request.

Now you're right that this is not necessarily a problem. But this is a side project that I just write in order to learn and explore stuff.

So I thought I would need to figure out a static capacity and was thinking about how to go about this. Then I realized I don't need a data structure that grows, but only a slice of a static memory region, which then means I don't need an arena (which can arbitrarily grow) in the first place.

Now I'm exploring all kinds of things that a web server does and where I would normally use a dynamically growable data structure. Like parsing JSON, form parameters, HTTP headers etc. And I can find natural or self imposed limits for all of those things.

For me, the most interesting thing about this isn't even performance. It's the mere fact that you _can_ figure out and design those limits. And the resulting code doesn't become complicated, but looks much simpler than I would have guessed. I really like the exactness of it all and how it changes the way I think about these things.

Re: Porting my JavaScript game engine to C for no reason

#132
post #42

Earlier quoted context omitted.

To be fair, they modified Impact _a lot_. In some of their development streams[1] you can see a heavily extended Weltmeister (Impact's level editor). Imho, that's fantastic! I love to see devs being able to adapt the engine for their particular game. Likewise, high_impact shouldn't be seen as a “feature-complete” game engine, but rather as a convenient starting point. [1] https://youtu.be/4lZfnM9Ubeo?t=3215

> To be fair, they modified Impact _a lot_. You can't polish a turd. There would've been no point in modifying the engine a bunch if you hadn't given them a useful base to work with.

> You can't polish a turd.

You absolutely can. Mythbusters proved it.

https://youtu.be/yiJ9fy1qSFI

Re: Porting my JavaScript game engine to C for no reason

#133

> My decision to sell it was met with a lot of backlash but was successful enough to launch me into a self-sustained career. As someone who is interested in eventually freeing myself from the corporate job and diving head-first into my side projects, I would love to hear more about this aspect. For some reason the idea of trying to charge folks for the work I would normally do for the fun of it on the side is dauntin…

It's perfectly reasonable to get compensated for the (good) work that you do if it's solving problems for someone, which you probably already know.

So I think it's important to figure out why the idea of doing that is daunting to you. Some common "reasons" are:

- People you interact with frequently tell you to not to do it.

- Not having all the skills to execute what you want to do well.

- Asking people for help feels embarrassing and/or is annoying to them.

- The fear of having your work judged by others.

- Losing the "safety" that part of, or all of, your current income offers; especially if you have dependents.

For most people (in the context of what you said), those aren't really good reasons—it's just because it's difficult to leave the comfort zone (nothing wrong with that) because that will require at least some degree of readjustment that seem "risky". With that mindset it's actually very difficult to ever find a good time to do what you _want_ to do because all opportunities appear to be risks instead.

On a somewhat related note, I think it's important to just do what you think is fun and show it to the world, but turning that into something that you can make a living with is an entirely different challenge.

Most people don't actually get to do what they love doing for a living; even if you do, having the pressure that is the expectations of paying customers and/or maintaining revenue could take that love away from you. That's absolutely not to say that you shouldn't—it's just something that's good to be aware of before you jump into it.

Re: Porting my JavaScript game engine to C for no reason

#134
post #11

Earlier quoted context omitted.

BMP coupled with 7Zip would outperform too (probably by a bigger margin). It just boils down to gzip vs gzip-replacement compressor.

Not to mention the part where adding compressors like this somewhat defeats the purpose of using a simple format like QOI (although at least zstd is faster than gzip, let alone 7zip). But if we're modifying things like that, then they might as well make use of Nigel Tao's improved QOIR format, and replace the LZ4 compressor it uses with zstd. That's probably faster and likely compresses better than QOI. [0] https://n…

Replacing lz4 with zstd will give you half the speed, with just better compression. https://gregoryszorc.com/blog/2017/03/07/better-compression-...

Re: Porting my JavaScript game engine to C for no reason

#135

Earlier quoted context omitted.

The original JavaScript engine “Impact” from 2010 is at the end of its life; the C rewrite “high_impact” is new and will (potentially) be around for as long as we have C compilers and some graphics API. The JavaScript engine had a lot of workarounds for things that are not necessary anymore and some things that just don't work that well with modern browsers. From the top of my head: - nearest neighbor scaling for pix…

I loved Impact. Now finding out you were working on an Impact2?! Any chance you're going to release it, even if its incomplete?

Sounds more like Impact2 is no longer being worked on

Re: Porting my JavaScript game engine to C for no reason

#136

Earlier quoted context omitted.

Googling your name reveals that you like to stir up drama. Please find another venue.

> Googling your name reveals that you like to stir up drama. Please find another venue. Kind of ironic, given that you claim to have been doxxed out of your own forum.

Your "portfolio page" is quite disrespectful and in line with your behaviour in this HN submission. You've made up too many blatantly obvious lies and are now stooping down to provocating a reaction, because you having nothing better to say. I don't think anyone should trust you.

Re: Porting my JavaScript game engine to C for no reason

#137

Earlier quoted context omitted.

> Googling your name reveals that you like to stir up drama. Please find another venue. Kind of ironic, given that you claim to have been doxxed out of your own forum.

Your "portfolio page" is quite disrespectful and in line with your behaviour in this HN submission. You've made up too many blatantly obvious lies and are now stooping down to provocating a reaction, because you having nothing better to say. I don't think anyone should trust you.

> Your "portfolio page" is quite disrespectful and in line with your behaviour in this HN submission.

Care to elaborate what is "disrespectful" about my own personal website? How did I offend you, specifically?

> You've made up too many blatantly obvious lies and are now stooping down to provocating a reaction, because you having nothing better to say. I don't think anyone should trust you.

I've cited a lot of news articles, blog posts, insights, even malware databases from multiple globally known and trusted security vendors.

What more do you want?

Re: Porting my JavaScript game engine to C for no reason

#138

Looks like it’s a great game engine. Why does the article state its near end of life? Are there new engines that are far better?

The original JavaScript engine “Impact” from 2010 is at the end of its life; the C rewrite “high_impact” is new and will (potentially) be around for as long as we have C compilers and some graphics API. The JavaScript engine had a lot of workarounds for things that are not necessary anymore and some things that just don't work that well with modern browsers. From the top of my head: - nearest neighbor scaling for pix…

[deleted]

Re: Porting my JavaScript game engine to C for no reason

#139
post #134

Earlier quoted context omitted.

Not to mention the part where adding compressors like this somewhat defeats the purpose of using a simple format like QOI (although at least zstd is faster than gzip, let alone 7zip). But if we're modifying things like that, then they might as well make use of Nigel Tao's improved QOIR format, and replace the LZ4 compressor it uses with zstd. That's probably faster and likely compresses better than QOI. [0] https://n…

Replacing lz4 with zstd will give you half the speed, with just better compression. https://gregoryszorc.com/blog/2017/03/07/better-compression-...

So to clarify: my suggested point of comparison was replacing QOI + 7Zip of GP with QOIR + zstd. QOIR already compresses better than QOI before the LZ4 pass, and zstd compresses faster than 7zip and often better. On top of that you can put zstd in the header option when streaming data on a browser so you don't need to increase the JS bundle or whatever if the use case is the web. So that's basically a guaranteed net improvement all around.

Second of all, the speed/compression trade-off with zstd can be tuned a lot. The "half as fast as LZ4" stat is for the fastest setting, but for the proposed comparison point of 7zip a slower setting with better compression ratio is likely perfectly fine.

[0] https://github.com/facebook/zstd/tree/dev?tab=readme-ov-file...

Post reply on HN