Managing memory with svg <image> elements

I am currently utilizing SVG-Edit to craft a rather large SVG image file. However, I've noticed that the memory usage appears to be excessive, leading me to question if this is normal or if there are optimizations that I may have overlooked.

Below is a breakdown showcasing the memory changes at each stage, observed using Firefox 10's about:memory page:

Stages:

  • Before: Prior to loading SVG-Edit
  • Ready : After SVG-Edit is loaded
  • Loading 35 images totaling 16.6MB *
  • Generating preview of the file *
  • Closing the preview *
  • Closing the tab and initiating FF memory cleanup via about:memory page

* Note that these stages involve my custom function, not SVG-Edit's

The increase in memory usage between the Ready and Load Images stages is quite significant, almost reaching 300 MB for loading just 16 MB of images! Although I utilize ObjectURL to load the images, it doesn't seem to be the sole cause. The spike during preview generation - where the ObjectURL array is transformed into data:uri - while expected due to embedding all images, still seems excessive. It's common for resulting SVGs to exceed 50MB in size due to this requirement.

Important to mention that SVG-Edit operates on DOM, not Canvas.

I welcome any guidance in identifying the root cause behind the escalating memory consumption.

Here's a simplified outline of the image loading process (triggered by the input change() event):

  • Set Image.src to objectURL
  • Assign Image.onload event to create SVGImage element with corresponding src, width, and height attributes derived from Image. Also execute revokeObjectURL()
  • Store SVGImage in global object array { imageID, <image> element, file handle }
  • Append SVGImages to SVG

Answer №1

The SVG size is 16MB, while the jump to 300MB is due to image surfaces containing pixel data at a rate of 4 bytes per pixel for the rendered image.

For example, a small SVG image with a simple 1000px by 1000px rectangle could be less than 500 bytes in size. However, once rendered, this would result in 4MB of pixel data...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Does an async function get automatically awaited if called in a constructor?

I am currently working on updating some code due to a library upgrade that requires it to be made async. The code in question has a base class that is inherited by other classes, and I need to call some functions in the constructor that are now asynchronou ...

I am interested in incorporating a condition to modify the image within this script or potentially generate a new one

I am looking to update an image based on the condition defined by val["id"]: if (val["id"] > 10) { //show the first image } else if (val["id"] > 20) { //show the second image } else { //show the third image }; I am struggling with some ...

Order the rows being inserted into a table by iterating through them using a foreach loop directly from the

I am currently working on a table that receives its data from a database. The table structure includes the typical header row, and then I use a foreach() loop to fetch information from an included file and display it in the table body (with a new row for e ...

What is the best way to display HTML code using Vue syntax that is retrieved from an Axios GET request

I am currently working on a project that involves a Symfony 5 and Vue 3 application. In this setup, a Symfony controller creates a form and provides its HTML through a JSON response. The code snippet below shows how the form HTML is returned as a string: i ...

Monitoring and recording the current line number during evaluation

Recently, I've been experimenting with eval to modify a $scope object named variables. This is the watcher I'm using: $scope.$watch(function () { return $scope.variables; }, function (variables) { console.log('changed!'); }, true) ...

Error encountered in Internet Explorer 11 - Access is forbidden - XMLHttpRequest

I am encountering a unique issue with IE11 and ajax. Most of the time, everything works as expected when I use the code below for my requests. However, I have noticed that when I try to use it in combination with a copy and paste function, an 'Access ...

In TypeScript, the Select element does not contain an options property

Having trouble iterating through a TypeScript array. Here are the methods I'm using: getNotification(evt: string, rowIndex: number) { console.log("Production order: law has changed to " + evt + " " + rowIndex); var select = document.getEleme ...

The app.html for the skygear/react-chat-demo is malfunctioning

I followed the instructions provided in the Skygear manual at https://docs.skygear.io/guides/advanced/server/ The skygear-server-darwin-amd64 started successfully. Then, I attempted to run the react-chat-demo project from https://github.com/skygear-de ...

The distance calculation is not functioning properly within the for loop

I am currently working on developing a geolocation test app. After finding some useful code for calculating the distance between two points using latitude and longitude coordinates, I am attempting to create a loop using a for loop to calculate the distan ...

Flash message fails to appear during page redirection

In my setup using a nodejs server and mysql database, whenever I successfully add new rows to the database, I populate the flash message success variable in this way: req.flash('success','New parts have been added to the database') I ...

jQuery droppable: Encounter of an unexpected TypeError: undefined lacks the characteristics of a function

I'm trying to implement drag and drop functionality on my website. However, I am encountering an error message in the console that says: Uncaught TypeError: undefined is not a function ... presentation-categories.js?version=1:23. The error occurs at ...

Can Page Transitions be implemented when linking to an external website?

I am aiming to create a login page that, when the user clicks the login button, redirects them to a web application via a different URL. I've observed that elaborate full-page transitions (like those shown in this example) are typically achieved by ma ...

Identifying Seating Arrangements at the Poker Table - Sit-and-Go Events

Note: The JavaScript code has been implemented based on the answer provided by ajrwhite. Hopefully, it proves helpful to someone. Link: http://codepen.io/eMineiro/pen/EKrNBe Be sure to open the CodePen console to see the examples in action. When playing ...

Issue Occurred when Trying to Import External Class in Vue Component

I am having trouble importing an external JavaScript file that contains a Form Class into a Vue Component. My File Structure is as follows: js - components -- dashboard --- dashboard.vue - app.js - form.js I have attempted to import the Form Class using ...

Iterate over a series of button elements within a loop in order to dynamically control corresponding input fields

Having trouble looping through an array with JavaScript/jQuery to display data and remove contents with button clicks. Original Code in Question HTML <textarea rows="4" cols="40" id="sds">Apple Banana Grape Orange</textarea> <input type=" ...

Having difficulties retrieving JSON data

I'm encountering an issue while trying to retrieve my JSON data using an AJAX request. JSON { "Ongoing": [ {"name": "meh"}, {"name": "hem"} ], "Completed": [ {"name": "kfg"}, {"name": "dkfgd"} ] } ...

Is there a way to extract all the class names from a JavaScript file?

I am currently working on developing a code to showcase all the public properties of a class that are available in a JavaScript file. As of now, the user has to manually input the name of the class in a text box. However, my goal is to enhance user experie ...

Getting the WatchPosition update just one time

I have implemented this code to continuously retrieve the first position and I need it to keep doing so. var init = function() { navigator.geolocation.getCurrentPosition(function(position) { new_position = position; }, onEr ...

Steps to create a hover effect that alters the appearance of another chosen "element"

For instance, I have two classes named A and B. I want to be able to change the appearance of B when I hover over it, such as its color or size. I am unsure if this can be achieved using CSS and the onmouseover event. I am including a snippet of code that ...

After subscribing, my Angular template fails to refresh

Currently, I am facing an issue with my Angular 17 project where the data fetched from the API is not updating the template. This means that despite receiving the data, I am unable to display it on the page. The code snippet below shows the service compon ...