HandyHands - Automatic handcrafting

by Qon

Automatically start handcrafting an item that is quickbar filtered (or in logistics requests) that you don't have enough of whenever your crafting queue is empty. Prioritises items in your cursor and what you need the most. It's like having logistics deliveries for early game!

Utilities
3 years ago
0.13 - 1.1
9.29K

b [Resolved] UPS Issues with Large Recipe Mods

4 years ago

Hey,

Looking around at a couple other bugs on the HH page, it seems like this is a relatively common issue - when multiple other mods that add recipes get added into the game, HH causes significant UPS drops. I did some performance profiling using the new performance profiler in 0.17, and the issues seem to be coming from the call to player.get_craftable_count, which, with my full set of Pyanodon's mods, takes around 1-3ms (!) to complete even for incredibly simple recipes like an iron pipe. Naturally, with a few hotbars of stuff, you're looking at dozens of ms (I see 50ms spikes while it's crafting on my save, and 10ms just idling as it still runs this every time even on filled-up items).

Personally, I was able to resolve this locally by altering the item loop in hh_player to pull out the inventory item count before the get_craftable_count call to see if it already exceeds the HH setting. Since most of the items on my hotbar are full most of the time, and they only drop when I'm building, and even then only one item at a time, this brings down the spikes to around 5ms, and now hits around 0.5ms when idle, which is much more usable.

I'd suggest doing the same thing in HH. Just pull the item count/setting checks out of the if statement and put a new condition prior to the get_craftable_amount call.

I'll report this performance bug in get_craftable_count on the Factorio forums sometime this weekend. It's probably searching through recipes that aren't handcraftable, and scanning huge iron refining recipe trees underneath iron plates.

4 years ago

I did some performance profiling using the new performance profiler in 0.17

How do I find it? Sounds awesome!

I'll report this performance bug in get_craftable_count on the Factorio forums sometime this weekend.

Please report back here with a link when you do, thanks!

I'll look into it, thanks for the help solving it <3

4 years ago

I implemented the suggested fix in 1.7.13 and improved code quality some.

4 years ago
(updated 4 years ago)

There's not really much documentation on the profiler. Here's the documentation page:

https://lua-api.factorio.com/latest/LuaProfiler.html

I basically did the below to the code (except with a lot more profilers). It's a bit crude, but it works, and you can see the UPS issues on a blank map if you just install some mods that include a ton of recipes (like Pyanodon's suite), then unlock all techs, then just autocraft something like iron pipes. I also had some other profilers going over the whole function. You can just write the profiler to the console and it'll print out a time:

if global.hhProfiler1 == nil then
    global.hhProfiler1 = game.create_profiler()
end
global.hhProfiler1.reset()
global.hhProfiler1.stop()

for item in list do
    if debugging then p.print('debug ' .. item) end
    -- Check that we can craft this item. If not, skip.
    global.hhProfiler1.restart()

    local canCraftSome = p.get_craftable_count(item) > 0

    global.hhProfiler1.stop()

    if p.force.recipes[item] ~= nil and ((canCraftSome and p.force.recipes[item].enabled == true) or p.cheat_mode) then
    ...

<After the loop>
log("HH PROFILER 1")
log(global.hhProfiler1)

New response