Skip to content

Keep a cache of usercmd_t's in cgame#854

Merged
slipher merged 1 commit intoDaemonEngine:masterfrom
slipher:cmdcache
May 16, 2023
Merged

Keep a cache of usercmd_t's in cgame#854
slipher merged 1 commit intoDaemonEngine:masterfrom
slipher:cmdcache

Conversation

@slipher
Copy link
Copy Markdown
Member

@slipher slipher commented May 7, 2023

Note that this code lives in the gamelogic, so we can use it immediately without needing a new engine version.

To boost perf by reducing the GetUsercmdMsg IPCs.
@illwieckz
Copy link
Copy Markdown
Member

illwieckz commented May 7, 2023

Check out #854. It should be even faster by requesting only one usercmd_t per frame, and doesn't require ABI changes.

That's an interesting trick. Especially since it can be used right now by mods.

Anyway, something my patch does (it's better seen on game side), is to entirely remove the call to trap_GetCurrentCmdNumber. Would you have a way to cache trap_GetCurrentCmdNumber as well?

Notice that even if your patch has the advantage to don't break compatibility, this keeps the crufty design and we may want to clean-up the engine at some point. One good example is that function returns a bool. Actually no one code in game code makes uses of that bool. And if I may imagine there may have been people wanting that bool return, the need for that bool return is only motivated by the fact the code has to check on engine side that your request is properly done on game side. By requesting the whole array once for all, the code is not only simpler, but it totally removes the need for any check, and then totally removes the bool return.

@slipher
Copy link
Copy Markdown
Member Author

slipher commented May 8, 2023

OK I made a cache for the number too. Unvanquished/Unvanquished#2684

@slipher
Copy link
Copy Markdown
Member Author

slipher commented May 8, 2023

Oh I only read your code just now; I see it uses the same approach for caching the command number.

Notice that even if your patch has the advantage to don't break compatibility, this keeps the crufty design and we may want to clean-up the engine at some point. One good example is that function returns a bool. Actually no one code in game code makes uses of that bool.

Well if the cgame doesn't do any error checking, so much the worse for it. But then the engine doesn't try too hard to report errors, either. Right now we have negative command numbers requested at the beginning of the match, which is an error that goes undetected. But it was convenient to implement the cache the same way as in the engine, so I didn't touch it for the moment.

The current design may be inefficient (when used naively), but I don't see anything crufty about it.

@illwieckz
Copy link
Copy Markdown
Member

Yeah, caching the number within a frame is easy to do (and to redo 😁️), but this still means two trapcalls are done per frame: trap_GetUserCmd and trap_GetCurrentCmdNumber. To only do one trap call I assume we have to add a trap_GetUserCmdWithNumber function (and break compat).

Copy link
Copy Markdown
Member

@illwieckz illwieckz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit annoyed that this patch not only keeps the convoluted code, but also makes it more convoluted.

But it has the huge benefit of being immediately usable by mods, and the performance boost is expected to be huge, so we better want to merge this as soon as possible.

I think that doesn't close the door for an engine redesign on that part but such redesign can wait once this is merged.

I haven't tested this patch.

LGTM.

@ghost
Copy link
Copy Markdown

ghost commented May 15, 2023

this at least would merit an overflow check, since I read "we assume it never decrease" well, yet it can.

@slipher
Copy link
Copy Markdown
Member Author

slipher commented May 15, 2023

this at least would merit an overflow check, since I read "we assume it never decrease" well, yet it can.

The case of the number resetting is already handled correctly UNLESS it resets less than 64 frames from the previous reset. Anyway the worst thing that can happen is wrong prediction.

@ghost
Copy link
Copy Markdown

ghost commented May 15, 2023

ok then.

@illwieckz
Copy link
Copy Markdown
Member

the worst thing that can happen is wrong prediction.

And basically a wrong prediction looks like a small lag from my experience at trying to optimizing this (and doing mistakes 😁️), so not a big deal.

@slipher slipher merged commit eb8fd9c into DaemonEngine:master May 16, 2023
@slipher slipher deleted the cmdcache branch April 26, 2024 00:09
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.

2 participants