Auto HUD

Auto HUD

69.4k Downloads

AutoHUD horribly inefficient

gittibene opened this issue ยท 2 comments

commented

Really enjoy the mod but AutoHUD eats CPU resources like crazy, what is going on here?
Like that's kinda suspicious levels of CPU time spent on rendering a simple UI?

https://spark.lucko.me/QnHu8DEG6F

commented

I investigated this a bit. The spark display is very misleading here. It shows how AutoHUD seemingly spends a lot of time (8.17%) in the method net.minecraft.client.gui.hud.InGameHud.wrapOperation$bck000$autohud$autoHud$wrapHotbar(). I assume that is what lead you to report this issue, so let's investigate. Here is that function:

    // Hotbar
    @WrapOperation(
            method = "render",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/client/gui/hud/InGameHud;renderHotbar(FLnet/minecraft/client/util/math/MatrixStack;)V"
            )
    )
    private void autoHud$wrapHotbar(InGameHud instance, float tickDelta, MatrixStack matrixStack, Operation<Void> original) {
        if (AutoHud.targetHotbar) {
            Hud.preInject(matrixStack, Component.Hotbar);

        }
        original.call(instance, tickDelta, matrixStack);
        if (AutoHud.targetHotbar) {
            Hud.postInject(matrixStack);
        }
    }

What this is doing (the "target hotbar" flag is true) is call preInject, call the original hotbar renderer, then call postInject. Both preInject and postInject do not even appear on the resulting graph; most of the time is spent drawing to the screen. This is all done by the game itself; the Mixin simply causes a single extra call frame wrapping this renderer.

In fact, I modified this method and the one that does the special "render items to a different framebuffer first, then re-render them with transparency" handling (net.minecraft.client.gui.hud.InGameHud.wrapOperation$zzg000$autohud$autoHud$transparentHotbarItems()). In both methods, I commented out everything custom and simply called the original method as the game would do without AutoHUD installed. That would still make spark show the result as AutoHUD, even though it immediately defers back to the game's renderer. The result shows that there is no statistically significant difference in performance between running with regular AutoHUD and "noop" AutoHUD; the time spent rendering is almost all due to the game itself.

The only place in which AutoHUD uses more time to render than the game itself is the previously mentioned extra framebuffer. I have to do that to allow for transparent items, and only do that if the transparency mode is enabled. This shows up in the profiler as mod.crend.autohud.component.Hud.drawExtraFramebuffer() (and prepareExtraFramebuffer()).

So unless I've made a major mistake here, I do not believe this to be an actual problem.

commented

Thanks a lot for this! I did some benchmarks with and without AutoHUD and don't see an actual difference in FPS. Have a great weekend!