We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parseExpr中使用了一个cacheExpr作为生成的代码的缓存。但是这个缓存的命中率很低,对于后面附的例子,命中率是0。其原因在于cacheExpr把所有的VM的id拼起来形成一个exprId作为key, 而对于ms-repeat每次生成的eachProxy的id都是不一样的。这样虽然每次循环的代码都是一样的,可是因为exprId不一样缓存无法命中。
parseExpr
cacheExpr
exprId
ms-repeat
eachProxy
我的改进思路如下,为每一次repeat展开所生成的eachProxy赋予一个“批次号”,用这个批次号参与exprId的构造,这样就能保证缓存的命中。
我的试验性修改方法如下:
bindingExecutor.repeat
case "add":
var batchId = '$repeatbatchId$' + Math.random() //新增代码 for (var i = 0, n = arr.length; i < n; i++) { var ii = i + pos var proxy = getEachProxy(ii, arr[i], data, last) proxy['$repeatbatchId'] = batchId //新增代码 proxies.splice(ii, 0, proxy) lastFn = shimController(data, transation, spans, proxy) }
var exprId = scopes.map(function(el) { return el.$repeatbatchId || el.$id.replace(rproxy, "$1") //如果存在$repeatbatchId则使用之 }) + code + dataType + filters
对于下面的测试用例,avalon.scan的耗时能减少约30%. 我对avalon整体的代码还是不熟悉,这里的修改不一定能适用所有的场景,仅供参考吧。
avalon.scan
avalon
测试用例
<!DOCTYPE HTML> <html> <head> <title>ms-repeat</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <script src="avalon.js" ></script> </head> <body > <div ms-controller="test"> <div ms-repeat-array="arrays"> <img ms-repeat="array" ms-src="{{el}}" style="width:150px ; height:150px" ms-click="imageClicked(el)" ms-visible="visible"/> </div> </div> <script> var vmodel = avalon.define("test", function(vm) { vm.arrays=[]; vm.imageClicked = function(src){ console.log(src + 'clicked!') } vm.visible = true }) for(var i=0 ; i<20 ; i++){ var arr = []; for(var j=0 ;j <30; j++){ arr.push("12.jpg"); } vmodel.arrays.push(arr); } setTimeout(function(){ // vmodel.arrays = [] } ,20000) var start = new Date().getTime(); avalon.scan(); var end = new Date().getTime(); console.log("avalon.scan cost " + (end - start) + "ms") </script> </body> </html>
The text was updated successfully, but these errors were encountered:
http://www.cnblogs.com/smark/archive/2013/01/23/2874012.html
Sorry, something went wrong.
缓存的命中率与缓存运行的时间长短及客户机访问相同数量从缓存读取的次数等因素有关,所以当缓存命中率低
时可以从以下两方面进行排查:
1.缓存运行的时间,时间越长命中率会越高
2.缓存设置的大小,缓存设置过小也会导致命中率低
(如服务器8G内存 服务器系统正常运行保留2G 网络游戏:4096M 单机游戏:1024M 启动盘:256-1024M)
已经修复 f889dc4
No branches or pull requests
parseExpr
中使用了一个cacheExpr
作为生成的代码的缓存。但是这个缓存的命中率很低,对于后面附的例子,命中率是0。其原因在于cacheExpr
把所有的VM的id拼起来形成一个exprId
作为key, 而对于ms-repeat
每次生成的eachProxy
的id都是不一样的。这样虽然每次循环的代码都是一样的,可是因为exprId
不一样缓存无法命中。我的改进思路如下,为每一次repeat展开所生成的
eachProxy
赋予一个“批次号”,用这个批次号参与exprId
的构造,这样就能保证缓存的命中。我的试验性修改方法如下:
bindingExecutor.repeat
,case "add":
分支, 为eachProxy增加$repeatbatchId属性parseExpr
,调整exprId
的构造逻辑对于下面的测试用例,
avalon.scan
的耗时能减少约30%. 我对avalon
整体的代码还是不熟悉,这里的修改不一定能适用所有的场景,仅供参考吧。测试用例
The text was updated successfully, but these errors were encountered: