diff --git a/dev.md b/dev.md index ff48877..4c5f32b 100644 --- a/dev.md +++ b/dev.md @@ -120,6 +120,8 @@ - 对象的非空判断用 `!obj`,字面量的非空判断用 `!isNil(value)`。 - 任何情况下都不建议写 `try-catch-finally`,哪怕有时会因为报错导致某些关键状态产生错误,产生错误就应该让用户去修,而不是让系统兜底。 +- 参考 `perf.md` 来了解一些细节上面的性能指南。 + ## 双端分离 样板将渲染端与数据端彻底分离: diff --git a/perf.md b/perf.md new file mode 100644 index 0000000..3f6a302 --- /dev/null +++ b/perf.md @@ -0,0 +1,13 @@ +# `Map.getOrInsert` vs `Map.getOrInsertComputed` + +- 使用 `Map.getOrInsert`: 数字、短字符串(约 100 以内)、布尔值、空数组、空对象、对象引用 +- 使用 `Map.getOrInsertComputed`: 长字符串、空 Set、空 Map、自定义类构建出的实例(new Class())、有内容的数组、有内容的对象、有内容的 Set、有内容的 Map。 +- 使用哪个都可以: 函数 + +注:如果是直接传引用,那么用 `Map.getOrInsert`,以上对比的是现场构建条件下的性能表现,而非直接传入引用,对比直接传入引用没有任何意义。 + +Benchmark: + +- [Benchmark1](https://www.measurethat.net/Benchmarks/Show/35964/1/getorinsert-vs-getorinsertcomputed-1) +- [Benchmark2](https://www.measurethat.net/Benchmarks/Show/35965/1/getorinsert-vs-getorinsertcomputed-2) +- [Benchmark3](https://www.measurethat.net/Benchmarks/Show/35966/1/getorinsert-vs-getorinsertcomputed-3)