• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Lua W3 handles instantiation

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,861
Hello, while I wanted to translate the Zwiebelchen's Threat System to Lua, during the Debug Board it checkes the handles that are existing in the map and to asign them an integer does an operation that involves creating 50 locations, get their handle ids and finally removing all of them every 0.05 seconds and display the result.

In the Jass version the result is around 500, it only changes a bit when a unit is created or removed in the game, but when I did the same thing in Lua, the numbers were totally different, it keeps increasing until reach some high value, in that case was about 55000, and then decreased to 0 and then increased again to about 110000 and then decreased to 0 and increased about to 170000, and again down to 0 and then up to 210000 and then I stopped.

I made a map to recreate that, I used GUI to be sure that the operation is the same in Jass and Lua, the results vary on if I null the locations after destroying them:
1684699563295.png



In the Jass version if I don't null the locations the result starts from about 230 and increases slowly, if I null the locations, the result increase even slower.
While in the Lua version if I don't nil the locations the result increases very fast until 110000 and then decreases and up again like I said earlier, if I nil the locations the process is the same, but the value that is reached before increasing again is lesser than before, something like 16000 at first.

THE RESULTS:

------------------------------------------------------------------------------------------------------------------------------------------------------------------
In Jass without nulling the locations:
1684700218399.png
1684700278039.png


------------------------------------------------------------------------------------------------------------------------------------------------------------------
In Jass with nulling the locations:
1684700347288.png
1684700388749.png


------------------------------------------------------------------------------------------------------------------------------------------------------------------
In Lua without niling the locations:
1684700520842.png
1684700571860.png

1684700691633.png


------------------------------------------------------------------------------------------------------------------------------------------------------------------
In Lua with niling the locations:
1684700775344.png

1684700826272.png

1684701031549.png


I'm not sure why is happening this, this is weird to me, with the handle ids being different between players in Lua, and also their instantiation, do you have any idea of why?
I share you the map to you can test it:
 

Attachments

  • W3 Handles.w3m
    16.9 KB · Views: 4
In Lua garbage collector decides when to free handleIds and with that when starting to reuse them.
In warcraft 3 V1.31 Lua that can be tested by forcing it, collectgarbage(). Right after a collectgarbage() the old handleIds are reused.

But in V1.31 it was on local demand, could result into desyncs. It was later swaped to a different behaviour and it was disallowed to call it.
 
Level 24
Joined
Jun 26, 2020
Messages
1,861
Location[50] is never being destroyed because index is set -1 immediatly. So Location[49] is first one getting destroyed.
A loop using custom Index variable from 1 to 50 would be more straight forward instead of using IntegerA + custom variable.
Oh I didn't notice that, I think that is the reason why the result kept increasing when I tested in Jass, and I did it in that way because I wanna do it similarly to Zwiebelchen's Threat System was doing it, I prefered use just a loop or while in case of Lua, but I wanted to keep it in GUI as much as possible.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,233
The Lua garbage collector seems to have throughput problems. Creating garbage for it to collect faster than it can iterate through the heap to check for garbage will result in the garbage collection cycle taking an excessively long time, possibly even never completing. Garbage is only removed once a garbage collection cycle completes.

To avoid this issue, recycling Lua tables rather than throwing them away is recommended. This might also apply to units and other types of handles which have some kind of Lua wrapper associated with them, but most maps are unlikely to hit throughput limits with such objects alone (playable maps do not cycle through hundreds of units a second).
 
Status
Not open for further replies.
Top