Eliminating Code Overhead by Jake Wharton

https://www.youtube.com/watch?v=b6zKBZcg5fk
笔记:

  1. new ArrayList<>(), 最好是给初始的capacity, 默认值是zero initial capacity.
    尽量避免之后调用add()操作, 造成的memory object copy引起的额外性能消耗.
    chromium写的好的代码长这样:
    protected static List processLogcat(List rawLogcat) {
        List out = new ArrayList(rawLogcat.size());
        for (String ln : rawLogcat) {
            ln = elideEmail(ln);
            ln = elideUrl(ln);
            ln = elideIp(ln);
            ln = elideMac(ln);
            ln = elideConsole(ln);
            out.add(ln);
        }
        return out;
    }
  1. new StringBuilder(), 最好给出初始的capacity, 默认值是16.
    尽量避免之后调用append()操作, 造成的memory object copy引起的额外性能消耗.
    最好是调用这个构造方法:
    public StringBuilder(String str) {
        super(str);
    }

The capacity of the new builder will be the length of the String plus 16.
chromium写的好的代码长这样:

    private String buildSuggestWhere(String selection, int argc) {
        StringBuilder sb = new StringBuilder(selection);
        for (int i = 0; i < argc - 1; i++) {
            sb.append(" OR ");
            sb.append(selection);
        }
        return sb.toString();
    }
  1. 学习了不同的方法调用对应bytecode上的4种类型.
Eliminating Code Overhead by Jake Wharton_第1张图片
1.png
Eliminating Code Overhead by Jake Wharton_第2张图片
2.png
Eliminating Code Overhead by Jake Wharton_第3张图片
3.png
Eliminating Code Overhead by Jake Wharton_第4张图片
4.png
Eliminating Code Overhead by Jake Wharton_第5张图片
5.png
Eliminating Code Overhead by Jake Wharton_第6张图片
6.png
Eliminating Code Overhead by Jake Wharton_第7张图片
7.png
8.png
Eliminating Code Overhead by Jake Wharton_第8张图片
9.png
Eliminating Code Overhead by Jake Wharton_第9张图片
10.png
Eliminating Code Overhead by Jake Wharton_第10张图片
11.png
Eliminating Code Overhead by Jake Wharton_第11张图片
12.png
Eliminating Code Overhead by Jake Wharton_第12张图片
13.png
Eliminating Code Overhead by Jake Wharton_第13张图片
14.png
Eliminating Code Overhead by Jake Wharton_第14张图片
15.png
Eliminating Code Overhead by Jake Wharton_第15张图片
16.png
Eliminating Code Overhead by Jake Wharton_第16张图片
17.png
Eliminating Code Overhead by Jake Wharton_第17张图片
18.png

----- DONE ----

你可能感兴趣的:(Eliminating Code Overhead by Jake Wharton)