Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
@trisha_gee#DevoxxUK
Refactoring to Java 8
Trisha Gee, JetBrains
@trisha_gee
trishagee.com
Why Java 8?
It’s Faster
•Performance Improvements in Common Data
Structures
•Fork/Join Speed Improvements
•Changes to Support Concurre...
Easy to Parallelize
Fewer lines of code
Minimizes Errors
Safety Check
Test Coverage
Performance Tests
Decide on the Goals
Limit the Scope
Morphia
https://github.com/mongodb/morphia
Refactoring!
Lambda Expressions
Automatic Refactoring
•Predicate
•Comparator
•Runnable
•etc…
Abstract classes
Advanced Search
Collections & Streams
Automatic Refactoring
•For loop to collect
•For loop to forEach
•…with and without Streams
Manual Refactoring
Optional
But what about performance?
Lambdas
0
20
40
60
80
100
120
140
160
180
Ops/ms Lambdas vs Anonymous Inner Classes
Anonymous Inner Class Lambda


http://www.oracle.com/technetwork/java/jvmls2013kuksen-2014088.pdf
0
2
4
6
8
10
12
14
16
18
20
single thread max threads
n...
0
50,000
100,000
150,000
200,000
250,000
300,000
350,000
400,000
450,000
500,000
Constant message Variable message
Ops/ms ...
Streams vs Iteration
0
1
2
3
4
5
6
7
8
9
Ops/ms Iterator vs Stream
for loop forEach()


Going parallel
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Serial Parallel
TimeTaken(seconds) map()
MacBook Surface


0
20
40
60
80
100
120
140
160
Serial Parallel
TimeTaken(millis) findAny()
MacBook Surface


Optional
0
50,000
100,000
150,000
200,000
250,000
300,000
350,000
Value not null Value null
Ops/ms Compare Constant Field Value wit...
0
50,000
100,000
150,000
200,000
250,000
300,000
Value not null Value null
Ops/ms Compare Variable Field Value with Null
N...
Summary
Sometimes new idioms decrease clutter
…but sometimes they don’t
Sometimes the new features improve
performance
0
20
40
60
80
100
120
140
160
180
Ops/ms Lambdas vs Anonymous Inner Classes
Anonymous Inner Class Lambda
…and sometimes they don’t
0
50,000
100,000
150,000
200,000
250,000
300,000
Value not null Value null
Ops/ms Compare Variable Field Value with Null
N...
Sometimes a new feature makes life easier
…sometimes not so much
Some refactoring can safely be done
automatically
…often you need a human brain
Conclusion
Should you migrate your code to Java 8?
It Depends
Always remember what your goal is
And compare results to it
Understand what may impact performance
And if in doubt, measure
Code may magically improve
Or you may expose areas for improvement
Your tools can help you
But you need to apply your brain too
http://bit.ly/refJ8
@trisha_gee
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Sie haben dieses Dokument abgeschlossen.
Lade die Datei herunter und lese sie offline.
Nächste SlideShare
Refactoring to Java 8 (QCon New York)
Weiter
Nächste SlideShare
Refactoring to Java 8 (QCon New York)
Weiter
Herunterladen, um offline zu lesen und im Vollbildmodus anzuzeigen.

5

Teilen

Refactoring to Java 8 (Devoxx UK)

Herunterladen, um offline zu lesen

- Highlight the performance benefits of using Java 8 - after all, you’ll probably have to persuade "The Management" that tampering with
existing code is worthwhile
- Demonstrate how to identify areas of code that can be updated to use Java 8 features, and how to pick which changes will give you the
most benefit
- Demonstrate how to automatically refactor your code to make use of features like lambdas and streams
- Cover some of the pros and cons of using the new features - including suggestions of when refactoring may NOT be the best idea.

Ähnliche Bücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Ähnliche Hörbücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Refactoring to Java 8 (Devoxx UK)

  1. 1. @trisha_gee#DevoxxUK Refactoring to Java 8 Trisha Gee, JetBrains @trisha_gee trishagee.com
  2. 2. Why Java 8?
  3. 3. It’s Faster •Performance Improvements in Common Data Structures •Fork/Join Speed Improvements •Changes to Support Concurrency •…and more http://bit.ly/refJ8
  4. 4. Easy to Parallelize
  5. 5. Fewer lines of code
  6. 6. Minimizes Errors
  7. 7. Safety Check
  8. 8. Test Coverage
  9. 9. Performance Tests
  10. 10. Decide on the Goals
  11. 11. Limit the Scope
  12. 12. Morphia https://github.com/mongodb/morphia
  13. 13. Refactoring!
  14. 14. Lambda Expressions
  15. 15. Automatic Refactoring •Predicate •Comparator •Runnable •etc…
  16. 16. Abstract classes
  17. 17. Advanced Search
  18. 18. Collections & Streams
  19. 19. Automatic Refactoring •For loop to collect •For loop to forEach •…with and without Streams
  20. 20. Manual Refactoring
  21. 21. Optional
  22. 22. But what about performance?
  23. 23. Lambdas
  24. 24. 0 20 40 60 80 100 120 140 160 180 Ops/ms Lambdas vs Anonymous Inner Classes Anonymous Inner Class Lambda  
  25. 25. http://www.oracle.com/technetwork/java/jvmls2013kuksen-2014088.pdf 0 2 4 6 8 10 12 14 16 18 20 single thread max threads nsec/op Performance of Capture anonymous(static) anonymous(non-static) lambda  
  26. 26. 0 50,000 100,000 150,000 200,000 250,000 300,000 350,000 400,000 450,000 500,000 Constant message Variable message Ops/ms Logging Performance Lambda Direct call  
  27. 27. Streams vs Iteration
  28. 28. 0 1 2 3 4 5 6 7 8 9 Ops/ms Iterator vs Stream for loop forEach()  
  29. 29. Going parallel
  30. 30. 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Serial Parallel TimeTaken(seconds) map() MacBook Surface  
  31. 31. 0 20 40 60 80 100 120 140 160 Serial Parallel TimeTaken(millis) findAny() MacBook Surface  
  32. 32. Optional
  33. 33. 0 50,000 100,000 150,000 200,000 250,000 300,000 350,000 Value not null Value null Ops/ms Compare Constant Field Value with Null Null check Optional  
  34. 34. 0 50,000 100,000 150,000 200,000 250,000 300,000 Value not null Value null Ops/ms Compare Variable Field Value with Null Null check Optional  
  35. 35. Summary
  36. 36. Sometimes new idioms decrease clutter
  37. 37. …but sometimes they don’t
  38. 38. Sometimes the new features improve performance
  39. 39. 0 20 40 60 80 100 120 140 160 180 Ops/ms Lambdas vs Anonymous Inner Classes Anonymous Inner Class Lambda
  40. 40. …and sometimes they don’t
  41. 41. 0 50,000 100,000 150,000 200,000 250,000 300,000 Value not null Value null Ops/ms Compare Variable Field Value with Null Null check Optional
  42. 42. Sometimes a new feature makes life easier
  43. 43. …sometimes not so much
  44. 44. Some refactoring can safely be done automatically
  45. 45. …often you need a human brain
  46. 46. Conclusion
  47. 47. Should you migrate your code to Java 8?
  48. 48. It Depends
  49. 49. Always remember what your goal is And compare results to it
  50. 50. Understand what may impact performance And if in doubt, measure
  51. 51. Code may magically improve Or you may expose areas for improvement
  52. 52. Your tools can help you But you need to apply your brain too
  53. 53. http://bit.ly/refJ8 @trisha_gee
  • Sam82

    Apr. 30, 2019
  • ConsiderAdolphus

    Aug. 1, 2016
  • nevzata74

    Jun. 21, 2016
  • dongwq

    Jun. 17, 2016
  • ramkumarkb

    Jun. 13, 2016

- Highlight the performance benefits of using Java 8 - after all, you’ll probably have to persuade "The Management" that tampering with existing code is worthwhile - Demonstrate how to identify areas of code that can be updated to use Java 8 features, and how to pick which changes will give you the most benefit - Demonstrate how to automatically refactor your code to make use of features like lambdas and streams - Cover some of the pros and cons of using the new features - including suggestions of when refactoring may NOT be the best idea.

Aufrufe

Aufrufe insgesamt

38.823

Auf Slideshare

0

Aus Einbettungen

0

Anzahl der Einbettungen

36.708

Befehle

Downloads

107

Geteilt

0

Kommentare

0

Likes

5

×