This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
derphorse's profile picture

org.luaj...lua_yield() part of Computercraft?(CC 1.58?) Tekkit (1.2.9f)

Started by derphorse, 08 May 2015 - 05:51 PM
derphorse #1
Posted 08 May 2015 - 07:51 PM
I am the server maintainer for a small Minecraft "network". We finally moved Tekkit to a dedicated server which allows me to optimize it.

JvisualVM shows this for CPU time:


Am I right in attributing the lua_yield() to CC?

Is there a best practice to lower the usage?(we have been going around and adding (longer)sleeps to certain programs like clocks)

Thank you for your time.
KingofGamesYami #2
Posted 08 May 2015 - 09:39 PM
Why are you concerned about the CPU time when Total Time(CPU) is 0.000 ms?
Bomb Bloke #3
Posted 09 May 2015 - 08:42 AM
Yes, that lua_yield() thread will be related to ComputerCraft, and indeed, you want it active as much as possible - because when it's not active, that's when CC is actually using your processor!

Is there a best practice to lower the usage?(we have been going around and adding (longer)sleeps to certain programs like clocks)

Pretty much that sort of thing, yeah… just make sure you're using the relevant event filter when you yield.

For example, a loop which uses this sort of construct:

while true do
  sleep(1)

  if rs.getInput("right") then
    print("Redstone on!")
  end
end

… will use more CPU time then:

while true do
  os.pullEvent("redstone")

  if rs.getInput("right") then
    print("Redstone on!")
  end
end

Another technique is to have systems turned off while they're not in use. This won't affect CPU usage much, but it'll save a little RAM. Scripts such as eg "elevator controllers" typically only need to be running when people are actively using them.