I think there are 2 things that could be improved:
- search radius could be limited to prevent freezes
- back pressure logic could be fixed because in this specific case one of inserters was throwing items in the direction of a corner transport belt which due to alignment never could hold 8 items (speculation) so once items were dumped that inserter would resume throwing more items. To help with detecting that belts are not straight in Factorio 1.1.100 i made LuaEntity::belt_shape read which you can use to detect a belt is corner and so the items limit may need to be lower. In some extreme cases it may happen that only 5 items are on a corner belt (given that items spacing is 64 positions, inner lane has length of 106 positions and outer lane has length of 295 positions, it may happen inner lane will have 1 item and outer lane will have 4 items)