Resource usage

RAM cache

The RAM consumption is often of high importance on an embedded device. This section explains the different RAM caches, which together account for a lot of Opera's memory requirements.

Document cache

The document cache holds the current pages and their document structure, and as much as possible of recently visited pages. It is allocated dynamically on the Opera process heap. The absolute minimum stored in this cache is the full text of the main document and the text of any CSS documents. The document structure is also stored in this cache, and will contain elements for all tags (real and implicit).

Text is stored in Unicode 16-bits/char, with some overhead per word and line, so this area normally requires four to six times the page's source size.

If the user has several windows open, even if hidden, the current pages of all windows will be in this cache.

For devices with limited RAM, we try to keep this area at a minimum. When we set the size to 200Kb, it will grow as needed, but space will be reclaimed immediately when the page is no longer current.

Note that not all memory allocated for a document is counted, for example, memory used by Java/ECMAScript is not included in the document's RAM cache usage.

Section Entry Default Description
[Cache] Document 400 Size of document RAM cache

Image cache

Opera holds decoded (uncompressed) images in the image cache. The size of the image cache is configurable. The image cache size limit is not strictly adhered to in Opera for Devices; it may be exceeded, if necessary, to show all images on the page.

For animated images, the image cache must also hold the various layers or frames.

All visible images must be entirely in the image cache. Once they are no longer visible they may be thrown out if new images cannot fit.

When Opera renders scaled images (typical scenario when using fit-to-screen), the complete, rendered image must be in the image cache, plus rendered, scaled segments of the image that is visible on screen.

Section Entry Default Description
[Cache] Figure 4000 Size of image RAM cache

Java/ECMAScript cache

JavaScript objects are stored on a garbage-collected heap. The number of live objects in the heap is the sum of the numbers of live objects for all documents that are kept in RAM (current documents and cached documents).

When the JavaScript heap is full, the garbage collector is run to reclaim objects that are no longer reachable. Following the collection, the heap is resized to accommodate 1.5 times as many objects as were found to be live by the garbage collector.

When a new document is loaded into Opera, the size of the JavaScript heap is checked against a fixed, heap-limit parameter. If the heap size exceeds the set limit, then documents are evicted from the memory cache and the JavaScript garbage collector is run repeatedly until the heap size no longer exceeds the limit, or there are no more documents that can be evicted.

Section Entry Default Description
[Cache] ECMAScript 400 The size of heap space allocated for scripts

Disk cache

The CDK is built with disk cache support. There is a section called [Disk Cache] in the opera.ini file that lets you enable/disable disk cache by setting Enabled accordingly. Disk cache is disabled by default. When disk cache is enabled, the parameter Size (see opera.ini) controls the size of the disk cache, and when disk cache is disabled, cache in held in RAM and the same parameter controls the size.

There is a separate setting for the size of the disk cache buffer. This buffer is used between flushes to disk. Only relevant when disk cache is enabled. The default value is 1024 (kilobytes). A large value will cause a higher memory consumption, but a lower frequency of disk writes, and conversely, a small value will use less memory but also more frequent disk writes.

This cache will contain raw data such as HTML, images and JavaScript from recently visited pages, which reduces the need for re-fetching data from the server when going back and forth in history.

Window history

The window history uses some memory. To affect how many history items are cached in each window, try changing the "Max Window History Lines" preference in opera.ini.

Summary

Note that not all memory allocated for a document is counted, for example, memory used by Java/ECMAScript is not included in the document's RAM cache usage.

Section Entry Default Description
[Cache] Document 400 Size of document RAM cache
[Cache] Figure 4000 Size of image RAM cache
[Cache] ECMAScript 400 Size of ECMAScript RAM cache

Settings files

As mentioned in the included files section, the $OPERA_HOME directory contains settings files used by Opera and must therefore be both read- and writable. For storage access policies it is good to know that these files will be updated by Opera without the end user's interaction.

If storage space is an issue, some of the settings file sizes can be limited by preferences in the opera.ini file. This is possible for the bookmarks file (bookmarks.ini) where the maximum number of bookmarks as well as maximum string lengths can be set. The global history file (global.dat) can be limited by setting the maximum number of items in it.

The files containing cookie data (cookies4.dat) and Wand data (wand.dat) have no size limits and might grow substantially. The other files can be expected not to grow significantly, although there are no specific size limits.

Although some of the settings files are generated at runtime by Opera if they do not exist at startup, backup to persistent storage can still be useful to preserve the user's data and settings. You might for instance consider backing up the following files:

The list of files needing backup might have to be extended for full backup depending on the user case, so please view the list of included files for further decisions. For instance, if you use Speed Dial the cache index file opthumb.dat and cache directory need backup, if Opera Turbo is used the file containing the client ID (optrb.dat) needs backup and if widgets are used at least the widget security policy file (widgets.xml) needs backup.

Summary

Memory implications of the configuration settings

Opera will allocate the document cache, the image cache and JavaScript storage from the heap on start-up and it will fill up as the user browses. When these areas are full, they will normally stay close to full, as memory is not re-claimed below the configured limits. When the user browses pages that are larger than the allowable space in the document cache and JavaScript storage, the area will grow further as needed. This is also true if the user opens several documents in several windows, as documents in all open windows are considered "current" and therefore locked in the document cache.

The cache sizes and disk cache usage can be controlled by the different preferences in the [Cache] and [Disk Cache] sections of opera.ini. Tuning these can lead to significant reductions in memory consumption, but will always be a trade-off with speed.

Storage element Typical RAM impact Heavy usage Comments
Document cache 400 5000 Not strict; may grow until system halts
Image cache 4000 4000 Strict
ECMAScript Heap 400 400 May grow but normally kept in this range
Various allocations 500 1000 Allocated by Opera at start-up and while browsing
Total 5300 10400  

Algorithms

Cache Strict Configurable Memory Cache policy
Document cache No Run-time RAM LRU
Image cache Yes Run-time RAM LRU
ECMAScript garbage collector No Somewhat RAM GC

Fixed memory limits

In addition to adjusting Opera configurations, it is possible to set upper limits on the amount of memory allocated by Opera, and the total heap size of the Opera process. For more information, please see the Out of Memory API section.

Dictionary

LRU
Least recently used and the object in a cache that will be thrown out first
GC
Garbage collector
Run-time
Value can be changed any time
Active document
The document with which the user is currently interacting