Quantcast
Channel: Questions in topic: "webgl"
Viewing all articles
Browse latest Browse all 2390

Do I need to prematurely optimize when doing large amounts of string handling?

$
0
0
I'm working on a game that involves a lot of text. Every user interaction (click, tap, keypress) results in the parsing and rendering of one or more documents that are written in a markup language. Most of the parsing and rendering involves replacing markup tags in the original document with a resultant string in the rendered document. All of this is done fairly easily if I liberally use ToString. All of this is done in very complex, convoluted ways if I can't use ToString. A couple key points leading up to my question: - WebGL is one of the game's targets. - Documents are only parsed after user interaction, so the parsing code that would contain a multitude of ToString calls only happens when the user clicks/taps the GUI (as opposed to repeatedly parsing the current document on every frame.) - The game will include a fair amount of per-frame updates as well; audio in addition to visual elements. The question is, do I need to adopt a "never call ToString" policy from the beginning, even if my ToString calls are intermittent? Will the garbage I accumulate between user interactions build up enough to cause frame rate drops and audio stuttering when GC kicks in? Will the garbage accumulate enough to cause the WebGL container to panic and exit due to eventually exceeding the memory cap? It's incredibly complex to parse a markup language without being able to create and pass around substrings. I'm prepared to go down that road if necessary. What I'd like to get a feel for is whether or not it's necessary. I don't want to spend months writing this code the "easy and correct" way only to find out that I've created a memory management nightmare to untangle, especially given the number of "lessons learned" articles I've read that say be mindful of allocations right from the start. Most of those seem written in the context of per-frame allocations. I guess I'm wondering two specific things in the context described above: - Is performance always GUARANTEED to be affected by the GC kicking in? - Will the GC kick in frequently enough to clean up my intermittently allocated strings so that I don't exceed the WebGL container's memory cap? **Addendum** One other detail I imagine worth mentioning is that, in order to get my parsed markup docs on screen, I have to make a guaranteed minimum of one ToString call. That one is unavoidable, so I'm guaranteed to feed GC no matter what I do. What I'm not clear on is whether there's some line that says, "If you feed GC more than this, you can expect it to interrupt your animations and audio." Is running GC the problem? Or is it the amount of garbage being cleaned up on a given run that's the problem? (Or is it both?)

Viewing all articles
Browse latest Browse all 2390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>