patchExists is detrimental to performance of string rendering in Render_Fonts.LUA
Source of Bug: https://git.do.srb2.org/SinnamonLat/srb2p-public/-/blob/master/Lua/RENDERER/Render_Fonts.LUA#L50 & https://git.do.srb2.org/SinnamonLat/srb2p-public/-/blob/master/Lua/RENDERER/Render_Fonts.LUA#L291
Because of how text is rendered by individual characters, each character in a string needs to have its corresponding font graphic cached, so long as there is a valid graphic for it. The problem occurs when we have to validate if the currently processed character has a valid graphic in the font, v.patchExists uses the performance-intensive W_LumpExists to validate graphic lumps, which means for every character in every string we are checking every lump in every loaded wad to find our font graphic, afaik we do not cache the result as well for quick access later.
This affects every instance of string drawing via the V_drawString global function call.
Possible Solutions
At this point, there are two possible solutions that I have come up with, though there may be more that can work:
Checking if cachePatch result is nil
local pp = v.cachePatch(prefix..ascii_03d[s:byte()])
if pp == nil
*handle invalid graphic*
end
*continue execution*
This solution matches current behavior and omits the need to use patchExists. However, in execution, this does not actually work, as evident by differing word wrapping in the skin select menu on the tip text. Perhaps even on invalid graphics cachePatch is returning something that isn't nil(This would go against wiki definition)?
Checking if processed character is within valid range
if s:byte() < 33 -- s is a character, byte() gives us ASCII code of character, values less than 33 are control codes and space
*handle invalid graphic*
end
local pp = v.cachePatch(prefix..ascii_03d[s:byte()])
This solution is functionally different but preserves proper formatting of the skin select tip text. It also has the added performance benefit of only cachingPatches when we actually need to.