2.2.6的addSearchPath多次会导致卡顿的BUG

BUG描述在3楼

https://github.com/chukong/quick-cocos2d-x/blob/c0c29ebab139db10a7af50a8b1270fe7bdc86dce/framework/cc/uiloader/CCSUILoader.lua

function CCSUILoader:parserJson(jsonVal)
    local root = jsonVal.nodeTree
    if not root then
        root = jsonVal.widgetTree
    end
    if not root then
        printInfo("CCSUILoader - parserJson havn't found root node")
        return
    end
    print("test LoadCCSJSON ----  parserJson xxxx1111  " )
    self:prettyJson(root)
    print("test LoadCCSJSON ----  parserJson 22222  " )
    local uiRoot = self:generateUINode(root)
print("test LoadCCSJSON ----  parserJson 3333  " )
    return uiRoot, root.options.adaptScreen
end

发现多次读取JSON文件后(几十次差不多) ,变的巨卡无比:有数据对比:

第一次的时候,self:generateUINode只用了 0.16秒...


07-01 11:34:39.317: D/cocos2d-x debug info(7834):   collectgarbage = test LoadCCSJSON ---- worldpanel 111111111111111111111111 ------LUA VM MEMORY USED: 19378.05 KB
07-01 11:34:39.327: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  uiloader11111 World.json
07-01 11:34:39.327: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  uiloader222222 World.json
07-01 11:34:39.327: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  CCSUILoader 1111  
07-01 11:34:39.327: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  CCSUILoader 222  
07-01 11:34:39.327: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  parserJson xxxx1111  
07-01 11:34:39.327: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  parserJson 22222  
07-01 11:34:39.337: D/cocos2d-x debug info(7834): cocos2d: padding: 0,0,0,0
07-01 11:34:39.487: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  parserJson 3333  
07-01 11:34:39.487: D/cocos2d-x debug info(7834):   collectgarbage = test LoadCCSJSON ---- worldpanel load 2222222222222222222 ------LUA VM MEMORY USED: 19650.60 KB


几十次读取后:变成 0.76秒 ,很是恐怖


07-01 12:02:36.177: D/cocos2d-x debug info(7834):   collectgarbage = test LoadCCSJSON ---- worldpanel 111111111111111111111111 ------LUA VM MEMORY USED: 20272.06 KB
07-01 12:02:36.187: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  uiloader11111 World.json
07-01 12:02:36.197: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  uiloader222222 World.json
07-01 12:02:36.197: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  CCSUILoader 1111  
07-01 12:02:36.197: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  CCSUILoader 222  
07-01 12:02:36.197: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  parserJson xxxx1111  

07-01 12:02:36.197: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  parserJson 22222  
07-01 12:02:36.957: D/cocos2d-x debug info(7834):  test LoadCCSJSON ----  parserJson 3333  
07-01 12:02:36.957: D/cocos2d-x debug info(7834):   collectgarbage = test LoadCCSJSON ---- worldpanel load 2222222222222222222 ------LUA VM MEMORY USED: 20545.08 KB



发觉读取文件完全不是瓶颈~~~,是非常的快,哪怕几十次之后,解析成显示对象就是个慢的地方


-- private
function uiloader:loadFile_(jsonFile)

    print("test LoadCCSJSON ----  uiloader11111 "..jsonFile)
    local fileUtil = cc.FileUtils:getInstance()
    local fullPath = fileUtil:fullPathForFilename(jsonFile)
    local jsonStr = fileUtil:getStringFromFile(fullPath)
    local jsonVal = json.decode(jsonStr)

print("test LoadCCSJSON ----  uiloader222222 "..jsonFile)
    return jsonVal
end

具体哪里变慢,还在查当中

发觉应该是uilabel的BUG了

cc.ui.UILabel.new({text = options.text,
            size = options.fontSize,
            color = cc.c3b(options.textColorR, options.textColorG, options.textColorB)}))

难道传说中的 CCLabelTTF 有内存泄露的问题,我还要的quick 2.2.6 …

找来原因了,原来是2.2.6的 cc.FileUtils:getInstance():addSearchPath 这个导致:



  for i=1,1000 do 
   cc.FileUtils:getInstance():addSearchPath("res/")
    cc.FileUtils:getInstance():addSearchPath("res/common/")
  end 

cc.uiloader:load(jsonFile)


调用多次就会导致uiloader load 渲染非常的慢

验证3.3已经没有这BUG了