Skip to content

Commit 220b52f

Browse files
author
philippe
committed
Follow up to r15253:
Having a one elt free lineF cache avoids many PA calls. This seems to slightly improve (a few %) a firefox startup. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15254 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent fb4e5b6 commit 220b52f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

helgrind/libhb_core.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,11 @@ static UWord read_twobit_array ( UChar* arr, UWord ix ) {
10071007
return (arr[bix] >> shft) & 3;
10081008
}
10091009

1010+
/* We cache one free lineF, to avoid pool allocator calls.
1011+
Measurement on firefox has shown that this avoids more than 90%
1012+
of the PA calls. */
1013+
static LineF *free_lineF = NULL;
1014+
10101015
/* Allocates a lineF for LineZ. Sets lineZ in a state indicating
10111016
lineF has to be used. */
10121017
static inline LineF *alloc_LineF_for_Z (LineZ *lineZ)
@@ -1015,7 +1020,12 @@ static inline LineF *alloc_LineF_for_Z (LineZ *lineZ)
10151020

10161021
tl_assert(lineZ->dict[0] == SVal_INVALID);
10171022

1018-
lineF = VG_(allocEltPA) ( LineF_pool_allocator );
1023+
if (LIKELY(free_lineF)) {
1024+
lineF = free_lineF;
1025+
free_lineF = NULL;
1026+
} else {
1027+
lineF = VG_(allocEltPA) ( LineF_pool_allocator );
1028+
}
10191029
lineZ->dict[0] = lineZ->dict[2] = lineZ->dict[3] = SVal_INVALID;
10201030
lineZ->dict[1] = Ptr2SVal (lineF);
10211031

@@ -1030,7 +1040,11 @@ static inline void clear_LineF_of_Z (LineZ *lineZ)
10301040
LineF *lineF = LineF_Ptr(lineZ);
10311041

10321042
rcdec_LineF(lineF);
1033-
VG_(freeEltPA)( LineF_pool_allocator, lineF );
1043+
if (UNLIKELY(free_lineF)) {
1044+
VG_(freeEltPA)( LineF_pool_allocator, lineF );
1045+
} else {
1046+
free_lineF = lineF;
1047+
}
10341048
lineZ->dict[0] = SVal_NOACCESS;
10351049
lineZ->dict[1] = SVal_INVALID;
10361050
}

0 commit comments

Comments
 (0)