Why double Still Outperforms BigDecimal: A Decade-Long Performance Comparison
Overview Many developers consider BigDecimal the go-to solution for handling money in Java. They often claim that replacing double with BigDecimal has fixed one or more bugs in their applications. However, I find this reasoning unconvincing. The issue may lie not with double but rather with how it was handled. Additionally, BigDecimal introduces significant overhead that may not justify its use. When asked to improve the performance of a financial application, I know that if BigDecimal is involved, it will eventually need to be removed. While it may not be the largest performance bottleneck initially, as we optimise the system, BigDecimal often becomes one of the main culprits. BigDecimal is Not an Improvement BigDecimal comes with several drawbacks. Here are some of its key issues: It has an unnatural syntax. The API is verbose and can be cumbersome to use. It uses more memory. BigDecimal objects consume more memory compared to primitive types. It ...