Optimizing your equals() methods with Pattern Matching - JEP Cafe #21
How can you write simple and performant equals() methods for your Java classes: the full tutorial.
Usually you do not write your equals() and hashCode() methods yourself. You delegate that to your IDE and forget about it. This JEP Café deep dives into the different solutions offered by Eclipse and IntelliJ, as well as Guava and Apache Commons Lang 3. It compares these solutions and checks the performance they offer on various real-life use cases. It also compares them with the Pattern Matching solution, available from Java 17 and Java 21.
⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯
0:00 Intro: designing equals() methods
1:13 Generating equals() and hashCode() methods
1:56 What could go wrong with a bad hashCode() method
4:31 Taking a look at the generated equals() methods
7:11 Checking the record and pattern matching implementations
9:33 What is predictive branching, what is the cost of a failing prediction?
12:41 Evaluating the cost of two failing predictions.
14:53 Evaluating the performance of equals() methods on simple data sets
16:07 First data set: all the objects are the same instance
16:46 Second data set: different instances carrying the same state
18:43 Third data set: different objects of the same type
20:41 Fourth data set: objects of different types
22:00 First conclusions on what patterns are the best
22:39 Adding glitches to the data sets
24:41 Results for first data set (same instances) with glitches
25:20 Results for second data set (equal instances) with glitches
26:07 Results for third data set (different instances) with glitches
28:30 Results for fourth data set (different types) with glitches
30:05 What conclusions can you draw from all these benches?
32:33 That’s it for today, talk to you soon!
⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯
◦ Pattern Matching for intanceof ➱
◦ Records ➱
◦ Record Patterns ➱
◦ Guava ➱
◦ Apache Commons Lang 3 ➱
◦ Eclipse IDE ➱
◦ IntelliJ IDE ➱
◦ JMH on GitHub, with doc and samples ➱
◦ Alexey Shipilev on JMH ➱
◦ ➱
◦ ➱
◦ JDK 21 ➱
◦ JDK 17 ➱
◦ OpenJDK ➱
◦ Oracle Java ➱
#Java #Java21 #OpenJDK #JDK #JDK21 #Collection #JEPCafe #insidejava
2 views
606
231
1 week ago 00:09:23 1
How to Find a Dropshipping Suppliers Today: Unveiling the Ultimate Guide😎
1 week ago 00:31:08 1
Хроники Поднебесной. Дети Тьмы Глава 13 / Chronicles of the Celestial Empire. Children of darkness13
1 week ago 00:05:47 1
Bumper Kitty - seo mao gone to bumper cars?
1 week ago 00:01:47 1
Secrets Revealed: Science of Sleep Patterns
1 week ago 00:10:01 1
The Animated History of Finland
1 week ago 00:01:45 1
Gothic Classic Khorinis Saga | Release Trailer
1 week ago 00:04:54 1
Decentralized Finance | Defi Apps | Defi and Blockchain
1 week ago 00:13:14 1
My First Watercooled PC Build ever! Intel Core I9 14900k | 128GB RAM | RTX 4090
1 week ago 01:04:20 1
Zohar Reading - Beresheet Aleph [Genesis, Part 1] - Special Book of Zohar Reading
1 week ago 00:02:36 1
Song Seung Heon And Oh Yeon Seo (Player Season 2 Master of Swindlers) Real Life Partner 2024
1 week ago 00:13:00 1
Free & Easy: Step-by-Step Guide to Earning $300 a Day With Google - Make Money Online
1 week ago 00:01:15 1
Ex-Marine Exposes Hidden Wellness Tips
1 week ago 00:03:14 1
1993 Chevrolet Corvette For Sale at Gateway Classic Cars of Orlando Stock#2652
1 week ago 00:15:54 1
The ONLY CS2 FPS BOOST GUIDE You’ll EVER NEED, Increase FPS, REDUCE Input Lag, & CS2 Optimization!