Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6979008

Reduce object allocation in BigDecimal.subtract() by providing "pure" implementation

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • 6-pool
    • 6-pool
    • core-libs
    • generic
    • generic

      BigDecimal.subtract(BigDecimal subtrahend) is currently implemented as:

          public BigDecimal subtract(BigDecimal subtrahend) {
              return add(subtrahend.negate());
          }

      subtrahend.negate() produces a new BigDecimal object since BigDecimal objects are immutable.

      This object allocation could be avoided by providing a "pure" implementation of subtract, similar to the "pure" implementation of BigDecimal.add(BigDecimal augend).

      A prototype of a "pure" BigDecimal.subtract(BigDecimal subtrahend) suggests an improvement of 1% - 2% in SPECjbb2005 performance on some hardware platforms.

            skuksenko Sergey Kuksenko
            huntch Charlie Hunt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: