Closed Bug 1435283 Opened 6 years ago Closed 6 years ago

use calloc when (re-)allocating PLDHashTable

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1452288
Tracking Status
firefox60 --- affected

People

(Reporter: froydnj, Assigned: froydnj)

Details

PLDHashTable::ChangeTable does:

  char* newEntryStore = (char*)malloc(nbytes);
  if (!newEntryStore) {
    return false;
  }

  ...

  memset(newEntryStore, 0, nbytes);

Newer versions of GCC are smart enough to optimize this to calloc(), which is probably more efficient--particularly for large allocations--because the OS zeroes memory pages all the time.  Looking at Windows Nightlies, however, I see that MSVC does not make the equivalent optimization.

Looking at a performance profile from jesup, https://perfht.ml/2BQB4BX , I see ~1/4 of the samples under ChangeTable being spent in vcruntime140.amd64.pdb.  I'm going to assume those are memset'ing the new table to zero, though I could just as well see them being in memcpy'ing old entries over.  Hard to tell without good symbols.

In any event, this is probably a reasonable change to make regardless, and it might just speed things up?
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.