getTokens() Slow

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

getTokens() Slow

Post by Tanthos »

I've been toying with macro that uses getTokens(). Unfortunately, I've found that it's extremely slow on some maps, and it seems unrelated to the number of tokens.

A tiny map with dozens of tokens took 3ms.
A huge map with a few tokens took 457ms.

Obviously, 457ms is way too much to handle, so I've been trying to work it down. I saw the old thread from wolph & CiF about distancePerCell, but that didn't fix it.

It seems like the issue is stemming from map size, because the time it takes to complete the function correlates directly with the size of the map. Is that reasonable to assume?

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: getTokens() Slow

Post by aliasmask »

getTokens() is wonky and I don't think I've ever seen it take 3ms before. I usually put in a range option to limit the number of tokens checked. Wouldn't hurt to specify the token layer either. The map size may matter if you have a lot of stamps on different layers, not sure. It may still see those trees on the object layer but will still go through the process to exclude them based on the parameters set.

User avatar
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

Re: getTokens() Slow

Post by Tanthos »

aliasmask wrote:getTokens() is wonky and I don't think I've ever seen it take 3ms before. I usually put in a range option to limit the number of tokens checked. Wouldn't hurt to specify the token layer either. The map size may matter if you have a lot of stamps on different layers, not sure. It may still see those trees on the object layer but will still go through the process to exclude them based on the parameters set.
I am giving it these parameters:

Code: Select all

json.set("{}", "layer", json.append("[]", "TOKEN"), "range", json.set("{}", "token", cToken, "distancePerCell", 0, "upto", 0, "metric", "ONE_ONE_ONE"))
The only factor that seems to be making a difference is the overall size of the map. Not sure why that would matter when it's only supposed to search within 0 spaces.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: getTokens() Slow

Post by aliasmask »

When you say map size, what is defining the size? All the maps are technically near infinite (but not really). Does your big map have vbl, fow on, stuff like that?

User avatar
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

Re: getTokens() Slow

Post by Tanthos »

I've even tried switching VBL, FOW, and the rest on and off, yet it doesn't seem to matter. I simply mean by size that there is a large amount of space between tokens, and much more of the area has been drawn upon.

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: getTokens() Slow

Post by JamzTheMan »

Try exporting that map and re-importing it (in same campaign and into a fresh one) to see what you get?

Also, I would have to take a look, but I'm going to hedge a guess that regardless of parameters, it's going to fetch all tokens and then do a foreach loop and iterate over them removing them by criteria.

It may do some prefilter by layer, pc/npc, etc but distance would have to be calculated. Try deleting all tokens/stamps on the other layers and see what happens?

Let us know and if we can narrow it down we can look into it more.
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

Re: getTokens() Slow

Post by Tanthos »

I am strongly leaning toward this being an issue of looping through the getTokens parameters. It's burdensome on the program, and I think that the distance parameter is particularly brutal on this specific map due to the large distances between tokens. I tried the exact code on a small map with almost six times the tokens and the run time was shorter than it was on the large map.

Post Reply

Return to “Macros”