Skip to content

Commit 049c12e

Browse files
committed
minor perf improvements related to issue #51
1 parent 6b36d2f commit 049c12e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/iso_alloc.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ INTERNAL_HIDDEN bit_slot_t iso_scan_zone_free_slot_slow(iso_alloc_zone *zone) {
741741

742742
INTERNAL_HIDDEN iso_alloc_zone *is_zone_usable(iso_alloc_zone *zone, size_t size) {
743743
/* This zone may fit this chunk but if the zone was
744-
* created for chunks more than N* larger than the
744+
* created for chunks more than (N * larger) than the
745745
* requested allocation size then we would be wasting
746746
* a lot of memory by using it. We only do this for
747747
* sizes beyond ZONE_1024 bytes. In other words we can
@@ -837,9 +837,9 @@ INTERNAL_HIDDEN iso_alloc_zone *iso_find_zone_fit(size_t size) {
837837
* slower iterative approach is used. The longer a
838838
* program runs the more likely we will fail this
839839
* fast path as default zones may fill up */
840-
if(size >= ZONE_512 && size <= ZONE_8192) {
840+
if(size >= ZONE_512 && size <= MAX_DEFAULT_ZONE_SZ) {
841841
i = _default_zone_count >> 1;
842-
} else if(size > ZONE_8192) {
842+
} else if(size > MAX_DEFAULT_ZONE_SZ) {
843843
i = _default_zone_count;
844844
}
845845
#endif
@@ -1038,6 +1038,7 @@ INTERNAL_HIDDEN INLINE size_t next_pow2(size_t sz) {
10381038
return sz + 1;
10391039
}
10401040

1041+
/* Populates the thread cache, requires the root is locked and zone is unmasked */
10411042
INTERNAL_HIDDEN INLINE void populate_thread_caches(iso_alloc_zone *zone) {
10421043
#if THREAD_SUPPORT && THREAD_CACHE
10431044
if(thread_bit_slot_cache.chunk == NULL) {
@@ -1051,6 +1052,11 @@ INTERNAL_HIDDEN INLINE void populate_thread_caches(iso_alloc_zone *zone) {
10511052
}
10521053
}
10531054

1055+
/* Don't cache this zone if it was recently cached */
1056+
if(thread_zone_cache_count != 0 && thread_zone_cache[thread_zone_cache_count - 1].zone == zone) {
1057+
return;
1058+
}
1059+
10541060
if(thread_zone_cache_count < THREAD_ZONE_CACHE_SZ) {
10551061
thread_zone_cache[thread_zone_cache_count].zone = zone;
10561062
thread_zone_cache[thread_zone_cache_count].chunk_size = zone->chunk_size;
@@ -1065,7 +1071,8 @@ INTERNAL_HIDDEN INLINE void populate_thread_caches(iso_alloc_zone *zone) {
10651071

10661072
INTERNAL_HIDDEN void *_iso_alloc(iso_alloc_zone *zone, size_t size) {
10671073
#if THREAD_SUPPORT && THREAD_CACHE
1068-
if(LIKELY(zone == NULL) && size <= SMALL_SZ_MAX && thread_bit_slot_cache.chunk_size >= size && thread_bit_slot_cache.chunk != NULL) {
1074+
if(LIKELY(zone == NULL) && size <= SMALL_SZ_MAX && thread_bit_slot_cache.chunk_size >= size &&
1075+
thread_bit_slot_cache.chunk != NULL) {
10691076
void *p = thread_bit_slot_cache.chunk;
10701077
thread_bit_slot_cache.chunk = NULL;
10711078
thread_bit_slot_cache.chunk_size = 0;
@@ -1143,10 +1150,10 @@ INTERNAL_HIDDEN void *_iso_alloc(iso_alloc_zone *zone, size_t size) {
11431150
zone = iso_find_zone_fit(size);
11441151
}
11451152

1146-
if(zone != NULL) {
1147-
/* We only need to check if the zone is usable
1148-
* if it's a custom zone. If we chose this zone
1149-
* then its guaranteed to already be usable */
1153+
/* We only need to check if the zone is usable
1154+
* if it's a custom zone. If we chose this zone
1155+
* then its guaranteed to already be usable */
1156+
if(LIKELY(zone != NULL)) {
11501157
if(zone->internally_managed == false) {
11511158
zone = is_zone_usable(zone, size);
11521159

0 commit comments

Comments
 (0)