Skip to content

Commit 15a6733

Browse files
committed
expression cache
expressions with the same signature are now cached! this dramatically improves performance on large v-repeat lists with multiple expressions.
1 parent 032a0de commit 15a6733

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/compiler.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function Compiler (vm, options) {
6363
// set compiler properties
6464
compiler.vm = el.vue_vm = vm
6565
compiler.bindings = makeHash()
66+
compiler.expCache = compiler.expCache || makeHash()
6667
compiler.dirs = []
6768
compiler.deferred = []
6869
compiler.computed = []
@@ -677,7 +678,11 @@ CompilerProto.defineMeta = function (key, binding) {
677678
*/
678679
CompilerProto.defineExp = function (key, binding, directive) {
679680
var filters = directive && directive.computeFilters && directive.filters,
680-
getter = ExpParser.parse(key, this, null, filters)
681+
exp = filters ? directive.expression : key,
682+
getter = this.expCache[exp]
683+
if (!getter) {
684+
getter = this.expCache[exp] = ExpParser.parse(key, this, null, filters)
685+
}
681686
if (getter) {
682687
this.markComputed(binding, getter)
683688
}

src/directives/repeat.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ module.exports = {
77

88
this.identifier = '$r' + this.id
99

10+
// a hash to cache the same expressions on repeated instances
11+
// so they don't have to be compiled for every single instance
12+
this.expCache = utils.hash()
13+
1014
var el = this.el,
1115
ctn = this.container = el.parentNode
1216

@@ -64,7 +68,8 @@ module.exports = {
6468
el : el,
6569
parent : this.vm,
6670
compilerOptions: {
67-
repeat: true
71+
repeat: true,
72+
expCache: this.expCache
6873
}
6974
}).$destroy()
7075
this.initiated = true
@@ -210,7 +215,8 @@ module.exports = {
210215
data: data,
211216
parent: this.vm,
212217
compilerOptions: {
213-
repeat: true
218+
repeat: true,
219+
expCache: this.expCache
214220
}
215221
})
216222

0 commit comments

Comments
 (0)