Closed Bug 115752 Opened 24 years ago Closed 24 years ago

gif_write : memory churn

Categories

(Core :: Graphics: ImageLib, defect, P3)

x86
Windows 2000
defect

Tracking

()

RESOLVED FIXED
mozilla0.9.8

People

(Reporter: dp, Assigned: dp)

Details

(Keywords: perf)

Attachments

(1 file, 1 obsolete file)

gif_write() allocates memory for prefix, suffix and stack for lzw decompression for every image. These buffers are fixed size 4097, 4097, 8194 bytes. We could recycle these buffers easily. We read about 120 image files on startup.
Status: NEW → ASSIGNED
Priority: -- → P3
Target Milestone: --- → mozilla0.9.8
Keywords: perf
Attached patch Reduce gif_write memory churn (obsolete) — Splinter Review
On startup this would reduce: 360 [120 * 3] allocations/free 2,063,760 [120 * 8k + 240 * 4k] of memory chrun
Ccing simon for sr=
+#define NBUCKETS 3 Prefer const PRInt32 kNumBuckets = 3; It's also the case that you can't have more than 32 buckets (limited by the mFlags), so you should comment this. + // Clear the buckets of memory we have for zlib + int ClearBuckets(); int? Also, what does the return value mean? You always return 0. + +#define IS_IN_USE(i) (mFlag & (1 << i)) +#define MARK_USED(i) mFlag |= (1 << i) +#define CLEAR_USED(i) mFlag &= ~(1 << i) Prefer inline functions (you are such the old unix hacker!). Then you can assert if i > 31. + nsGifAllocator() : mFlag(0) You shoudl initialize mLock to nsnull too. + for (int i = 0; i < NBUCKETS; i++) PRInt32? + mMemBucket[i] = 0; minor niggle; I prefer using nsnull for null pointers, to disambiguate with coding mistakes where you thought mMemBucket[] was a value, rather than a pointer. + int freeAllocatedBucket = -1; PRInt32? +static inline void +gif_free(void *ptr) +{ ... + if (!gGifAllocator) + gGifAllocator = new nsGifAllocator; ... Is it ever worth making the allocator in a gif_free? If you can't guarantee you've called gif_calloc before, you might as well just free(). Finally, do we want to hook up this cache to the memory flusher? It could hold up to 128K of memory.
This keeps only 16k (not 128k). For now it gets freed at module shutdown. Later we will think about rolling a timer and cleaning it up.
Attachment #62109 - Attachment is obsolete: true
Comment on attachment 62150 [details] [diff] [review] Includes comments from Simon r=pavlov
Attachment #62150 - Flags: review+
Kill those 'returns' in the inline methods, and sr=sfraser
Removed the returns. Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Hey dp, you left a naked printf in the checkin, and it's spewing dozens of messages into the console while running the page-loader test (libpr0n/decoders/gif/GIF2.cpp DEBUG: global_colormap - 16 [4 x 4] DEBUG: global_colormap - 1024 [256 x 4] DEBUG: global_colormap - 1024 [256 x 4] DEBUG: global_colormap - 1024 [256 x 4] DEBUG: global_colormap - 512 [128 x 4] If someone kills that printf then mark this fixed again.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
seawood checked in a fix for this, BTW
Thanks seawood.
Status: REOPENED → RESOLVED
Closed: 24 years ago24 years ago
Resolution: --- → FIXED
The Image Conversion Library component is going away.
Component: Image Conversion Library → ImageLib
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: