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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P3
    • 6-pool
    • Affects Version/s: 6-pool
    • Component/s: 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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: