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?
getTokens() Slow
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: getTokens() Slow
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.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: getTokens() Slow
I am giving it these parameters: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.
Code: Select all
json.set("{}", "layer", json.append("[]", "TOKEN"), "range", json.set("{}", "token", cToken, "distancePerCell", 0, "upto", 0, "metric", "ONE_ONE_ONE"))
Re: getTokens() Slow
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?
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: getTokens() Slow
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.
- JamzTheMan
- Great Wyrm
- Posts: 1872
- Joined: Mon May 10, 2010 12:59 pm
- Location: Chicagoland
- Contact:
Re: getTokens() Slow
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.
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
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork
Re: getTokens() Slow
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.