Why 50K Records Took 40 Seconds: The Hidden Cost of List.contains() in Loops
A permission sync task processing 50,000 records ran in 40 seconds despite sub-second SQL queries; profiling revealed the bottleneck was an O(n²) List.contains() inside a stream filter, and replacing the List with a HashSet cut the diff calculation from 38 seconds to milliseconds, demonstrating how data structure choice dominates batch performance.
