Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

How to improve the performance of a large custom sheet?

1516226542

Edited 1516328248
Michael C.
Sheet Author
Hey guys, over the past 2 years I have written a custom, private character sheet for my games that has blown in size quite a lot. I was thinking about polishing it and making it public, but I'm having some issues about the performance. Compared to a normal standard character sheet (only the most basic things, around 2000 lines) my custom one has noticeably worse performance. Opening a character takes around 1-2 seconds longer and doing prep work as gm generally feels a lot slower. Some data about my custom sheet: It tries to automate as much of the rules of the system as possible. The approach is to simplify things like e.g. combat so that players do not have to keep in mind all the boni / mali that factor into their current combat numbers. The system is quite rule-heavy, hence the blown size. ~ 23.500 lines of code in total (Main sheet), 1.71mb filesize ~ 5.340 lines of code | Workerscripts ~ 3950 attributes | On average a player has around 200-400 of those saved with actual values ~ 1.600 lines of code (CSS), 52kb filesize 1 backgroundimage at 196kb size 1 logo at 52kb size Several graphical icons at ~ 1kb size If anyone wants to see the code: HTML Sheet: <a href="https://gist.github.com/ArkFox/581d3ab0e95c13e8a28" rel="nofollow">https://gist.github.com/ArkFox/581d3ab0e95c13e8a28</a>... CSS: <a href="https://gist.github.com/ArkFox/08f82eb8c6b4ae3b927" rel="nofollow">https://gist.github.com/ArkFox/08f82eb8c6b4ae3b927</a>... Imgur album with 53 pictures detailing how exactly the sheet looks like: <a href="https://imgur.com/a/ea8YB" rel="nofollow">https://imgur.com/a/ea8YB</a> The pictures are 13 months old, so not everything is still exactly the same but most of the sheet still looks like that. Warning though: The charsheet (attribute names, comments, etc.) is in german and the descriptions in the imgur album are in german as well. But that shouldn't be too much of a problem for a quick look. I'm thinking about rewriting the character sheet and polishing it. When I started 2+ years ago I knew very little about programming, so I'm sure some mistakes can be attributed to the lack of knowledge that I had in the past. Still, I'm no expert. My question for the more experienced character sheet developers is what the worst offenders are in terms of character sheet performance and what I should look to improve when rewriting the code.
1516228151
Pat S.
Forum Champion
Sheet Author
Have you looked into using sheetworkers instead of autocalc? If no, you should. I hear it speeds up complex sheets.
1516228990

Edited 1516229273
Michael C.
Sheet Author
Oh yeah, forgot to clarify that. Around 90% of all calculations are via sheetworkers (the ~4.700 lines of code of workerscripts), other 10% are autocalc because of convenience. Might look into switching those to sheetworkers as well, but those still left as autocalc really aren't that many. Maybe two dozen fields.
1516229212
Pat S.
Forum Champion
Sheet Author
WoW.
1516229485
[Deleted]
Sheet Author
API Scripter
The SWRPG character sheet used to be very slow because it was over 20k lines of code, honestly you just need to trim the code and try to offload it to an API script when possible. Now the SWRPG sheet is under 9k lines and it runs a lot faster. The more rule heavy the sheet, the slower it will run, no way to change that.
I remember it correctly that API scripts are for paying subscribers only? I was thinking about making my sheet public and this would be quite a negative for me if I'd have to hide functionality behind a paywall. Not that I mind personally since I'm a pro subscriber, but I know that not everyone is.
1516230910
Pat S.
Forum Champion
Sheet Author
The SWRPG requires the API script because of the dice the system requires. The API script helps make the game run smoother, if I understand it correctly.
1516237689

Edited 1516238225
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Heh, think I just responded to your reddit post on this. But on the off chance that you don't check reddit that much, or somehow two people are asking the same question, I'll drop my response here too: One thing I question is this bit: ~ 4.700 lines of code | Sheetworkers ~ 640 lines of code | JavasSript (One feature only: inventory management) The only javascript that character sheets accept is sheetworkers, so I'm not really sure what your 640 lines of non-sheetworker are doing. As for actual suggestions on improvement. Here's my take: Get rid of all your autocalc fields. Autocalc throws a massive amount of calculation at the sheet when it is first opened by a player/gm. You don't have many of them, but they add up quickly. Anything that you can do via autocalc can be done a lot more quickly and reliably via sheetworkers in my opinion (This is a somewhat contested viewpoint on the matter, see some of Brian's responses around the forum for a different take). Are your sheetworkers programmed as nested getAttrs and setAttrs? In other words do you getAttrs for a few attributes, set things based on that, then rely on the change event from that to cascade to any further attributes that need to be calculated? If so, I'd highly recommend switching to a single getAttrs/setAttrs model where you get all the attributes you could possibly need and then do any and all calculations necessary and then do a single setAttrs with the results of the calculations. This is much faster as a getAttrs/setAttrs takes about the same amount of time whether you are interacting with 1 attribute or a couple hundred. So, if you do getAttrs 100 times, each for a single attribute, it'll take 100 times as long, but if you do a single getAttrs getting the values of 100 attributes it takes something like 1.000005X as long (note using the American decimal point) as getting a single attribute. The same math occurs with with setAttrs. Finally, if you can find a way to convert your background image to css, I'd recommend that. I noticed a pretty good improvement in the performance of the sheet I'm working on when I got rid of most of the image calls and switched to css created shapes. I know this one may not be feasible though, as css can only do so much in the way of images, especially since we can't use svg's in the character sheet. And some additions in relation to some of the comments in this thread. You really don't need to try and off load calculations to the API. Sheetworkers will actually run quicker than an API script for the same calculation in general. This is because 1) the API runs server side, and so you are only ever getting a fraction of a core dedicated to your script's calculations, whereas sheetworkers run client side, and so have a greater percentage of a core that is probably dedicated to them; and 2) an API script needs to filter through all the objects on the tabletop to interact with the objects you want to change whereas a sheetworker is already bound to the sheet it needs to manipulate, so you just need to get the values of the attributes. Using the single getAttrs/setAttrs model I mentioned above, you can essentially write your sheetworkers as synchronous code instead of worrying about the problems of asynchronous code, and so do the calculations in the same manner as you would for an API, and remove the reason for sheetworkers to be slower than an API script. As you noted this also prevents your sheet from only being usable by pro members.
1516279049

Edited 1516279080
Michael C.
Sheet Author
Hey! Yeah, we wrote each other on reddit :D But thanks for your answer! But since others might be interested in this I'll answer here as well. &gt;&gt; The only javascript that character sheets accept is sheetworkers, so I'm not really sure what your 640 lines of non-sheetworker are doing. I wasn't very clear on that part, those 640 lines are sheet workers as well as I've implemented TheAaronSheet for my inventory management.&nbsp; &gt;&gt; Get rid of all your autocalc fields. Even if those are only max. two dozen fields, I'll keep it in mind and get rid of all of them. &gt;&gt; Are your sheetworkers programmed as nested getAttrs and setAttrs? No, that's not an issue but definitely good to keep in mind. &gt;&gt; Finally, if you can find a way to convert your background image to css That's what I've been thinking already. Try to trim the filesize of the total sheet as best as possible, including the graphics.
1516299660
GiGs
Pro
Sheet Author
API Scripter
The wiki says you only need worry about autocalc fields slowing you down if you have like hundreds or thousands of them. Will they really make that much of a difference? One thing I'd recommend: post your sheet on gist or pastebin, and ask for hints on how to optimise it. Chances are there are ways to streamline your code. Also, that's a LOT of attributes. If only 2-400 are used by characters, what are the other 3500? It maybe be there's an alternate approach (maybe via sheet workers) that eliminates the need for a lot of those.
1516310725

Edited 1516310804
Michael C.
Sheet Author
&gt;&gt;&nbsp;The wiki says you only need worry about autocalc fields slowing you down if you have like hundreds or thousands of them. Will they really make that much of a difference? I already noticed an improvement when ~ 1,5 years ago I switched ~ 80 autocalc fields completely to workersheets so I'd say yes, they do make a difference.&nbsp; &gt;&gt;&nbsp;Also, that's a LOT of attributes. That's because all those attributes are distinct spells/skills/abilities the player could choose for his character and ~ 50% of those are used further down the line for automatic calculations like e.g. combat modificators, the other ~50% are simply there for the player to remember that he has that fluff ability. Your average player only uses a small selection out of all the possibile spells/skills so that's where the number of 200-400 attributes with actual values comes from. The sheet tries to include the entire ruleset with all it's nooks and crannies. I already got the tip to outsource some of these to API scripts, but that's not an option as I don't want to hide funtionality behind a subscription when I release the sheet to the public.
1516325438
GiGs
Pro
Sheet Author
API Scripter
Thats interesting to note about the autocalc fields, thanks. Regarding the attributes, I was thinking that - depending on the kind of data they are storing - you might be able to do that more efficiently through sheetworkers.&nbsp; But anyway, it's hard to give concrete suggestions without seeing the code. Once you add it to the charsheet repository, it'll be public, so there's no harm in sharing it ahead of time.
HTML Sheet:&nbsp; <a href="https://gist.github.com/ArkFox/581d3ab0e95c13e8a28" rel="nofollow">https://gist.github.com/ArkFox/581d3ab0e95c13e8a28</a>... CSS:&nbsp; <a href="https://gist.github.com/ArkFox/08f82eb8c6b4ae3b927" rel="nofollow">https://gist.github.com/ArkFox/08f82eb8c6b4ae3b927</a>... Imgur album with 53 pictures detailing how exactly the sheet looks like: <a href="https://imgur.com/a/ea8YB" rel="nofollow">https://imgur.com/a/ea8YB</a> Warning though: The charsheet (attribute names, comments, etc.) is in german and the descriptions in the imgur album are in german as well. But that shouldn't be too much of a problem.
While I can't help w/ making the code more efficient, something you can try:&nbsp; Use Firefox Quantum.&nbsp; It has helped a number of users speed up their character sheet access.