Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Eliminating Code Overhead (Square HQ 2015)

Eliminating Code Overhead (Square HQ 2015)

The CPU, RAM, and disk are finite resources that are often taken for granted as unbounded. Not only is this obviously untrue, but the use of these resources directly affects the most important resource on a mobile device: the battery. This talk will focus on techniques that both libraries and applications can implement to ensure their effect is in general without overhead.

Video: https://youtu.be/b6zKBZcg5fk

54879f243e5b72eedb2d379bed6fda27?s=128

Jake Wharton
PRO

June 25, 2015
Tweet

Transcript

  1. Eliminating Code Overhead Jake Wharton

  2. CPU

  3. Memory CPU

  4. Memory CPU I/O

  5. Memory CPU I/O Battery

  6. Battery Memory CPU I/O

  7. Battery Battery Memory CPU I/O

  8. Battery Battery Memory CPU I/O

  9. Battery Battery Memory CPU I/O

  10. Battery Battery Battery Memory CPU I/O

  11. Battery Battery Battery Memory CPU I/O

  12. Battery Battery Battery Memory CPU I/O

  13. Memory CPU I/O

  14. Memory CPU I/O

  15. • Do not nest multi-pass layouts • Lazily compute complex

    data when needed • Cache heavy computational results for re-use • Consider RenderScript for performance • Keep work off of the main thread Memory CPU I/O
  16. • Use object pools and caches to reduce churn •

    Be mindful of the overhead of enums • Do not allocate inside the draw path • Use specialized collections instead of JDK collections when appropriate (SparseArray) Memory CPU I/O
  17. Memory CPU I/O • Batch operations with reasonable back-off policies

    • Use gzip or binary serialization format • Cache data offline with TTLs for reloading • Use JobScheduler API to batch across OS
  18. I/O Memory CPU What's next after macro?

  19. I/O Memory CPU What's next after macro? • Move on

    to so-called micro
  20. I/O Memory CPU What's next after macro? • Move on

    to so-called micro • Spectrum of optimizations, not binary
  21. I/O Memory CPU What's next after macro? • Move on

    to so-called micro • Spectrum of optimizations, not binary • Do not blindly apply to everything, only when appropriate
  22. I/O Memory CPU What's next after macro? • Move on

    to so-called micro • Spectrum of optimizations, not binary • Do not blindly apply to everything, only when appropriate • Multiple micro-optimizations can improve like a macro
  23. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  24. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  25. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  26. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  27. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  28. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  29. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  30. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  31. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  32. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  33. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  34. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  35. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  36. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  37. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  38. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  39. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  40. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  41. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  42. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  43. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  44. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  45. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  46. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  47. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  48. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  49. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  50. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  51. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  52. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  53. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  54. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  55. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  56. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  57. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  58. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  59. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  60. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  61. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  62. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  63. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  64. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  65. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  66. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  67. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  68. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  69. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  70. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  71. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  72. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  73. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  74. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  75. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }
 return unmodifiableList(names);
 }
  76. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>();


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  77. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  78. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  79. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  80. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  81. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  82. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  83. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  84. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  85. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  86. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty
  87. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty
  88. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty
  89. Jimmy•McNulty public String names(List<User> users) {
 StringBuilder builder = new

    StringBuilder();
 for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  90. Jimmy•McNulty public String names(List<User> users) {
 StringBuilder builder = new

    StringBuilder();
 for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•
  91. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,• Jimmy•McNulty,•
  92. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,• Stringer•Bell Jimmy•McNulty,•
  93. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,• Stringer•Bell Jimmy•McNulty,•
  94. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,• Stringer•Bell Jimmy•McNulty,•
  95. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Stringer•Bell Jimmy•McNulty,•
  96. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Stringer•Bell Jimmy•McNulty,•
  97. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Stringer•Bell Jimmy•McNulty,•
  98. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell
  99. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell
  100. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell
  101. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell Jimmy•McNulty,•Stringer•Bell,•
  102. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,• Jimmy•McNulty,•Stringer•Bell,•
  103. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,• Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•
  104. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,• Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•
  105. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,• Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•
  106. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•
  107. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•
  108. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•
  109. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland
  110. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland
  111. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland
  112. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland,•
  113. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland,•
  114. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland,• Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland,•D'Angelo•Barksdale
  115. Jimmy•McNulty,•Stringer•Bell,•Bunk•Moreland,•D'Angelo•Barksdale public String names(List<User> users) {
 StringBuilder builder = new

    StringBuilder();
 for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  116. public String names(List<User> users) {
 StringBuilder builder = new StringBuilder();


    for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  117. public String names(List<User> users) {
 int avg = 17; //

    Determined by exact science.
 StringBuilder builder = new StringBuilder(avg * users.size());
 for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  118. public String names(List<User> users) {
 int avg = 17; //

    Determined by exact science.
 StringBuilder builder = new StringBuilder(avg * users.size());
 for (User user : users) {
 if (builder.length() > 0) builder.append(", ");
 builder.append(user.name);
 }X
 return builder.toString();
 }X
  119. for (int x = 0; x < valueCount; x++) {


    cleanFiles[x] = new File(directory, key + "." + x);
 dirtyFiles[x] = new File(directory, key + "." + x + ".tmp");
 }X
  120. for (int x = 0; x < valueCount; x++) {


    StringBuilder b1 = new StringBuilder();
 b1.append(key);
 b1.append(".");
 b1.append(x);
 cleanFiles[x] = new File(directory, b1.toString());
 StringBuilder b2 = new StringBuilder();
 b2.append(key);
 b2.append(".");
 b2.append(x);
 b2.append(".tmp");
 dirtyFiles[x] = new File(directory, b2.toString());
 }X
  121. for (int x = 0; x < valueCount; x++) {


    StringBuilder b1 = new StringBuilder();
 b1.append(key);
 b1.append(".");
 b1.append(x);
 cleanFiles[x] = new File(directory, b1.toString());
 StringBuilder b2 = new StringBuilder();
 b2.append(key);
 b2.append(".");
 b2.append(x);
 b2.append(".tmp");
 dirtyFiles[x] = new File(directory, b2.toString());
 }X
  122. for (int x = 0; x < valueCount; x++) {


    StringBuilder b = new StringBuilder();
 b.append(key);
 b.append(".");
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString());
 }X
  123. for (int x = 0; x < valueCount; x++) {


    StringBuilder b = new StringBuilder();
 b.append(key);
 b.append(".");
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString());
 }X
  124. StringBuilder b = new StringBuilder();
 b.append(key);
 b.append("."); for (int x

    = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString());
 }X
  125. StringBuilder b = new StringBuilder();
 b.append(key);
 b.append("."); for (int x

    = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString());
 }X
  126. StringBuilder b = new StringBuilder();
 b.append(key);
 b.append("."); int truncateTo =

    b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString());
 }X
  127. StringBuilder b = new StringBuilder();
 b.append(key);
 b.append("."); int truncateTo =

    b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString());
 }X
  128. StringBuilder b = new StringBuilder();
 b.append(key);
 b.append("."); int truncateTo =

    b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  129. StringBuilder b = new StringBuilder();
 b.append(key);
 b.append("."); int truncateTo =

    b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  130. StringBuilder b = new StringBuilder(key.length() + 6);
 b.append(key);
 b.append("."); int

    truncateTo = b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  131. StringBuilder b = new StringBuilder(key.length() + 6);
 b.append(key);
 b.append("."); int

    truncateTo = b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  132. StringBuilder b = new StringBuilder(key);
 b.append("."); int truncateTo = b.length();

    for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  133. StringBuilder b = new StringBuilder(key);
 b.append("."); int truncateTo = b.length();

    for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  134. StringBuilder b = new StringBuilder(key);
 b.append("."); int truncateTo = b.length();

    for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); public StringBuilder(String str) Constructs a string builder initialized to the contents of the specified string. The initial capacity of the string builder is 16 plus the length of the string argument.
  135. StringBuilder b = new StringBuilder(key);
 b.append("."); int truncateTo = b.length();

    for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); public StringBuilder(String str) Constructs a string builder initialized to the contents of the specified string. The initial capacity of the string builder is 16 plus the length of the string argument.
  136. StringBuilder b = new StringBuilder(key);
 b.append("."); int truncateTo = b.length();

    for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString());
 b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  137. StringBuilder b = new StringBuilder(key).append("."); int truncateTo = b.length(); for

    (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString()); b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());
 for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  138. private int headerOffset;
 private int headerTop;
 private int animationHeight;
 


    @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 
 setTitle(getResources().getString(R.id.title));
 getWindow().setStatusBarColor(getResources().getColor(R.color.blue));
 
 headerOffset = getResources() .getDimensionPixelSize(R.dimen.header_offset);
 headerTop = getResources() .getDimensionPixelSize(R.dimen.header_top);
 animationHeight = getResources() .getDimensionPixelSize(R.dimen.animation_height);
 }X
  139. private int headerOffset;
 private int headerTop;
 private int animationHeight;
 


    @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 Resources res = getResources();
 
 setTitle(getResources().getString(R.id.title));
 getWindow().setStatusBarColor(getResources().getColor(R.color.blue));
 
 headerOffset = getResources() .getDimensionPixelSize(R.dimen.header_offset);
 headerTop = getResources() .getDimensionPixelSize(R.dimen.header_top);
 animationHeight = getResources() .getDimensionPixelSize(R.dimen.animation_height);
 }X
  140. private int headerOffset;
 private int headerTop;
 private int animationHeight;
 


    @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 Resources res = getResources();
 
 setTitle(res.getString(R.id.title));
 getWindow().setStatusBarColor(res.getColor(R.color.blue));
 
 headerOffset = res.getDimensionPixelSize(R.dimen.header_offset);
 headerTop = res.getDimensionPixelSize(R.dimen.header_top);
 animationHeight = res.getDimensionPixelSize(R.dimen.animation_height);
 }X
  141. private int headerOffset;
 private int headerTop;
 private int animationHeight;
 


    @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 Resources res = getResources();
 
 setTitle(res.getString(R.id.title));
 getWindow().setStatusBarColor(res.getColor(R.color.blue));
 
 headerOffset = res.getDimensionPixelSize(R.dimen.header_offset);
 headerTop = res.getDimensionPixelSize(R.dimen.header_top);
 animationHeight = res.getDimensionPixelSize(R.dimen.animation_height);
 }
  142. public boolean validIndices(int[] indices, String string) {
 for (int index

    : indices) {
 if (index < 0 && index >= string.length()) {
 return false;
 }X
 }X
 return true;
 }X
  143. public boolean validIndices(int[] indices, String string) {
 int len =

    string.length();
 for (int index : indices) {
 if (index < 0 && index >= len) {
 return false;
 }X
 }X
 return true;
 }X
  144. public boolean validIndices(int[] indices, String string) {
 int len =

    string.length();
 for (int index : indices) {
 if (index < 0 && index >= len) {
 return false;
 }X
 }X
 return true;
 }X
  145. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0; i < strings.size(); i++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X
  146. public boolean firstShorterThan(List<String> strings, int max) {
 int i =

    0;
 while (i < strings.size()) {X
 if (strings.get(i).length() > max) {Y
 return i;
 }X
 i++;
 }X
 return -1;
 }X
  147. public boolean firstShorterThan(List<String> strings, int max) {
 int i =

    0;
 while (true) {X
 if (!(i < strings.size())) {
 break;
 }Y
 if (strings.get(i).length() > max) {Y
 return i;
 }X
 i++;
 }X
 return -1;
 }X
  148. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0;ciy<sstrings.size();xi++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X
  149. public boolean firstShorterThan(List<String> strings, int max) {
 int size =sstrings.size();

    for (int i = 0;ciy< size;xi++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X
  150. public boolean firstShorterThan(List<String> strings, int max) {
 int size =sstrings.size();

    for (int i = 0;ciy< size;xi++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X
  151. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0, size = strings.size();ciy< size;xi++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X
  152. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0, size = strings.size();ciy< size;xi++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X
  153. None
  154. invokestatic static methods

  155. invokestatic static methods class Test {
 public static void main(String...

    args) {
 staticMethod();
 } 
 public static void staticMethod() {
 System.out.println("Hello, static method!");
 }
 }
  156. invokestatic static methods public static void main(java.lang.String...); Code: 0: invokestatic

    #2 // Method staticMethod:()V 3: return
  157. invokestatic static methods invokespecial constructors private methods super methods

  158. invokestatic static methods invokespecial constructors private methods super methods Test();

    Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return
  159. invokestatic static methods invokespecial constructors private methods super methods invokevirtual

    other class methods
  160. invokestatic static methods invokespecial constructors private methods super methods invokevirtual

    other class methods class Test {
 public static void main(String... args) {
 new Test().method();
 }
 
 public void method() {
 System.out.println("Hello, method!");
 }
 }
  161. invokestatic static methods invokespecial constructors private methods super methods invokevirtual

    other class methods public static void main(java.lang.String...); Code: ... 8: aload_1 9: invokevirtual #4 // Method method:()V
  162. invokestatic static methods invokespecial constructors private methods super methods invokevirtual

    other class methods invokeinterface interface methods
  163. invokestatic static methods invokespecial constructors private methods super methods invokevirtual

    other class methods invokeinterface interface methods class Test {
 public static void main(String... args) {
 List<String> names = Arrays.asList("Alice", "Bob", "Eve");
 int size = names.size();
 System.out.println(size);
 }
 }
  164. invokestatic static methods invokespecial constructors private methods super methods invokevirtual

    other class methods invokeinterface interface methods public static void main(java.lang.String...); Code: ... 23: aload_1 24: invokeinterface #7, 1 // InterfaceMethod java/util/List.size:()I
  165. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X
  166. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address
  167. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity Activity ContextThemeWrapper Context Object
  168. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity Activity ContextThemeWrapper Context Object
  169. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address Object.toString 101 MyActivity Activity ContextThemeWrapper Context Object
  170. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address Object.toString 101 Object.hashCode 102 MyActivity Activity ContextThemeWrapper Context Object
  171. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address Object.toString 101 Object.hashCode 102 ... MyActivity Activity ContextThemeWrapper Context Object
  172. Method Address Object.toString 101 Object.hashCode 102 ... public class MyActivity

    extends Activity { @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X MyActivity Activity ContextThemeWrapper Context Object
  173. Method Address Object.toString 101 Object.hashCode 102 Context.getResources 201 ... public

    class MyActivity extends Activity { @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X MyActivity Activity ContextThemeWrapper Context Object
  174. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X MyActivity Activity ContextThemeWrapper Context Object Method Address Object.toString 101 Object.hashCode 102 Context.getResources 201 ...
  175. Method Address Object.toString 101 Object.hashCode 102 ContextTW.getResources 301 ... public

    class MyActivity extends Activity { @Override protected void onCreate(Bundle bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X MyActivity Activity ContextThemeWrapper Context Object
  176. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address Object.toString 101 Object.hashCode 102 ContextTW.getResources 301 ... MyActivity Activity ContextThemeWrapper Context Object
  177. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X MyActivity Activity ContextThemeWrapper Context Object Method Address Object.toString 101 Object.hashCode 102 ContextTW.getResources 301 ...
  178. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X MyActivity Activity ContextThemeWrapper Context Object Method Address MyActivity.toString 501 Object.hashCode 102 ContextTW.getResources 301 ...
  179. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity.toString 501 Object.hashCode 102 ContextTW.getResources 301 ...
  180. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity.toString 501 Object.hashCode 102 ContextTW.getResources 301 ... getResources();
  181. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity.toString 501 Object.hashCode 102 ContextTW.getResources 301 ... getResources(); Method table lookup
  182. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity.toString 501 Object.hashCode 102 ContextTW.getResources 301 ... getResources(); Method table lookup Jump
  183. public class MyActivity extends Activity { @Override protected void onCreate(Bundle

    bundle) {
 super.onCreate(bundle);
 Resources res = getResources(); // ...
 }X @Override public String toString() {
 return "MyActivity";
 }X }X Method Address MyActivity.toString 501 Object.hashCode 102 ContextTW.getResources 301 ... getResources(); getResources(); getResources(); getResources(); getResources(); Method table lookup Jump Method table lookup Jump Method table lookup Jump Method table lookup Jump Method table lookup Jump
  184. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0; i < strings.size(); i++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X 
 strings.size()
  185. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0; i < strings.size(); i++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X strings.size()
  186. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0; i < strings.size(); i++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X strings.size() Class lookup
  187. public boolean firstShorterThan(List<String> strings, int max) {
 for (int i

    = 0; i < strings.size(); i++) {
 if (strings.get(i).length() > max) {
 return i;
 }X
 }X
 return -1;
 }X strings.size() Method table lookup Jump Class lookup
  188. What about JIT & AOT compilers?

  189. Resources res = getResources();

  190. Resources res = getResources(); public Resources getResources() {
 return mResources;


    }X private Resources mResources;
  191. Resources res = mResources; private Resources mResources;

  192. Resources res = mResources; private Resources mResources; mResources

  193. Resources res = mResources; private Resources mResources; mResources Memory lookup

  194. Resources res = mResources; private Resources mResources; mResources Memory lookup

    Copy to local
  195. Resources res = mResources; private Resources mResources; mResources Memory lookup

    Copy to local mResources mResources mResources mResources
  196. Resources res = mResources; private Resources mResources; mResources Memory lookup

    Copy to local mResources mResources mResources mResources Memory lookup Copy to local Memory lookup Copy to local Memory lookup Copy to local Memory lookup Copy to local
  197. for (int i = 0; i < strings.size(); i++)

  198. for (int i = 0; i < strings.size(); i++) @Override

    public int size() {
 return ;
 } int size; 
 size
  199. for (int i = 0; ix< strings. ;yi++) int size;

    size
  200. for (int i = 0; ix< strings.size;yi++) int size; size

  201. for (int i = 0; ix< strings.size;yi++) int size; size

    Memory lookup Copy to local
  202. for (int i = 0; ix< strings.size;yi++) int size; size

    Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy to local size Memory lookup Copy size Memory lookup ookup Copy to local size Memory
  203. for (int i = 0; ix< strings.size;yi++) int size;

  204. for (int i = 0, size = strings.size; ix< size;yi++)

    int size;
  205. for (int i = 0, size = strings.size; ix< size;yi++)

    int size; Memory lookup Copy to local size
  206. StringBuilder b = new StringBuilder(key).append("."); int truncateTo = b.length(); for

    (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString()); b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());
 for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  207. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (User user : users) {
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  208. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (Iterator<User> iter = users.iterator(); iter.hasNext(); ) {
 User user = iter.next();
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  209. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (Iterator<User> iter = users.iterator(); iter.hasNext(); ) {
 User user = iter.next();
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  210. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (Iterator<User> iter = users.iterator(); iter.hasNext(); ) {
 User user = iter.next();
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  211. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (Iterator<User> iter = users.iterator(); iter.hasNext(); ) {
 User user = iter.next();
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  212. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (Iterator<User> iter = users.iterator(); iter.hasNext(); ) {
 User user = iter.next();
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  213. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (Iterator<User> iter = users.iterator(); iter.hasNext(); ) {
 User user = iter.next();
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  214. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (int x = 0, size = users.size(); x < size; x++) {
 User user = users.get(x);
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  215. public List<String> names(List<User> users) {
 List<String> names = new ArrayList<>(users.size());


    for (int x = 0, size = users.size(); x < size; x++) {
 User user = users.get(x);
 names.add(user.name);
 }X
 return unmodifiableList(names);
 }X
  216. StringBuilder b = new StringBuilder(key).append("."); int truncateTo = b.length(); for

    (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString()); b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  217. int valueCount = this.valueCount; File directory = this.directory; File[] cleanFiles

    = this.cleanFiles; File[] dirtyFiles = this.dirtyFiles; StringBuilder b = new StringBuilder(key).append("."); int truncateTo = b.length(); for (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString()); b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  218. StringBuilder b = new StringBuilder(key).append("."); int truncateTo = b.length(); for

    (int x = 0; x < valueCount; x++) {
 b.append(x);
 cleanFiles[x] = new File(directory, b.toString()); b.append(".tmp");
 dirtyFiles[x] = new File(directory, b.toString()); b.setLength(truncateTo);
 }X
  219. What else? • Polymorphic virtual method calls • Monomorphic vs.

    bimorphic vs. megamorphic • Concurrency implications & locks • Read/write when lock, act out of lock • synchronized vs. concurrent lock types
  220. None
  221. jakewharton jakewharton jakewharton twitter.com/ google.com/+ .com Eliminating Code Overhead