[PATCH] Wasted memory use storing path copies in node tree
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 12 Aug 2011 11:04:42 +0000 (11:04 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 12 Aug 2011 11:04:42 +0000 (11:04 +0000)
When creating the node tree, every node stores a copy of its full path table. e.g. for node("admin.network.wireless"), node.path = { "admin", "network", "wireless" }

This value is not used anywhere, and likely may be from before the addition of the treecache lookup table? In any instance, I've searched high and low and see nothing ever referencing any node's path via the path member. It
eats a good chunk of memory though and as such I believe it should be removed.

I've tested every page in the admin-full module after removing it and all seem to function properly.

libs/web/luasrc/dispatcher.lua

index e29bd52..0162407 100644 (file)
@@ -612,28 +612,23 @@ function node(...)
        return c
 end
 
-function _create_node(path, cache)
+function _create_node(path)
        if #path == 0 then
                return context.tree
        end
 
-       cache = cache or context.treecache
        local name = table.concat(path, ".")
-       local c = cache[name]
+       local c = context.treecache[name]
 
        if not c then
-               local new = {nodes={}, auto=true, path=util.clone(path)}
                local last = table.remove(path)
+               local parent = _create_node(path)
 
-               c = _create_node(path, cache)
-
-               c.nodes[last] = new
-               cache[name] = new
-
-               return new
-       else
-               return c
+               c = {nodes={}, auto=true}
+               parent.nodes[last] = c
+               context.treecache[name] = c
        end
+       return c
 end
 
 -- Subdispatchers --