While building a small game, a general performance related question about the Canvas API came up: I am clearing and drawing on only a small space of a large canvas. Does the large size of the canvas slow down performance in such a case or does only the amount of drawn pixels matter? E.g. is the entire canvas redrawn when something changes?
Does Canvas Size Matter for Performance?
1.9k Views Asked by nexus At
1
There are 1 best solutions below
Related Questions in HTML
- How to store a date/time in sqlite (or something similar to a date)
- How to use custom font during html to pdf conversion?
- Storing the preferred font-size in localStorage
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- Is there any way to glow this bulb image like a real light bulb
- With non-graphical maps in Leaflet, zoomDelta doesn't work
- What can I do to improve my coding on both html and css
- Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
- Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
- Displaying a Movie List on a Website Using Jinja2 and Bootstrap
- How to redirect to thank you page after submitting a Google form embedded into a Google Site?
- Storing selected language in localStorage
- Fences (parenthesis, braces) in HTML and MathML
- Understanding Scroll Anchoring Behavoir
Related Questions in PERFORMANCE
- Upsert huge amount of data by EFCore.BulkExtensions
- How can I resolve this error and work smoothly in deep learning?
- Efficiently processing many small elements of a collection concurrently in Java
- Theme Preloader for speed optimization in WordPress
- I need help to understand the time wich my simple ''hello world'' is taking to execute
- Non-blocking state update
- Do conditional checks cause bottlenecks in Javascript?
- Performance of sketch drastically decreases outside of the P5 Web Editor
- sample query for review for improvement on big query
- Is there an indexing strategy in Postgres which will operate effectively for JOINs with ORs
- Performance difference between two JavaScript code snippets for comparing arrays of strings
- C++ : Is there an objective universal way to compare the speed of iterative algorithms?
- How to configure api http request with load testing
- the difference in terms of performance two types of update in opensearch
- Sveltekit : really long to send the first page and intense CPU computation
Related Questions in CANVAS
- Random number generator in Python Canvas
- When I use electron js and canvas in node js, I get a rebuild module error
- How to set an individual mouse scroll on two different canvases that are connected to separate frames but the frames are one on top of eachother?
- Positioning for sliders and canvas
- How to perfectly align textarea and canvas fillText
- Rust Ownership Challenges in Drawing Application: Need Assistance with Code Section
- Zoom In/Out particular Object with Touch in Fabric JS
- How to send a big array to a client faster
- Android: How to scale a bitmap to fit the screen size using canvas?
- How can i resize canva and send resized data to database?
- Given a convex polygon as a set of edges how to fill the area inside depending on the distance to the closest edge
- SigmaJS: Create a snapshot of "sigma-containter"
- Draw local image on canvas using react-native-canvas
- Rotating multiple objects around the origin (JavaScript Canvas)
- How to proper rotate object with a 45-degree angle using OrbitControls?
Related Questions in JSPERF
- What is the difference between Run and Quick Run in jsperf
- Why a hard-coding switch performs better at restricted shallow copying?
- how to use complexity-report tool on a js project
- Faster loop: foreach vs some (performance of jsperf is different than node or chrome)
- Why is Array.prototype.push faster than variable declaration
- Why does a custom splice function outperform native splice when the array size is lower than 3-5000?
- What is the most efficient way to create diff patch between 2 JavaScript objects?
- Which JS benchmark site is correct?
- No Browserscope shown in jsperf test case
- function declaration and function expression performance difference
- What's the relationship between ops/second and percentage slower in JSPerf?
- Performance measure giving different values for same operation
- The academically correct way to benchmark JavaScript code?
- JasperReport cannot run on Jboss6.0 but woeks fine on tomcat 7
- Testing purescript functions in jsPerf
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
As a general rule of thumb, performance is effected by the resolution of the images you are drawing and the size of the canvas. But most devices have hardware to handle the drawing and can easily refresh the display they use with plenty of time spare for extra bling.
The biggest bottle neck is the interface between the Graphics hardware and the device's main memory. If all your graphics can fit into the device's GPU memory you will not have any real performance issues. But if you start drawing more images than can fit into the the graphics memory you will see a major performance drop as the device moves data in and out of graphics memory. There is no easy way to know what the memory capacity of a device is via javascript.
So in short its not the number of pixels that you draw that matter, it is the number of unique pixels/images you draw. The effect can be very dramatic, adding just 1K of extra pixels over the GPU capacity can more than half the frame rate even though you may actually be drawing less pixels in total.
Reducing the size of individual images helps the system manage resources. Rather than one large bitmap that may have to be swapped out to make room for just one small bitmap, cut the larger bitmap into smaller ones so the change over is quicker.
GPUs work in blocks of pixels 2, 4, 8, 16, 32, 64, 128, ... and on in powers of two for either width and height. It is much more efficient to use images of these sizes. Having a 130*130 pixel image may actually require 256*256 (or 256*196 depending on the type of GPU) pixels in memory to store on the GPU ram while reducing the image to 128*128 will fit neatly and not waist GPU RAM.
Don't reference patterns that you don't use, fonts, and SVG images also take up space in GPU memory that is related to their pixel size not their actual memory foot print. Don't leave the canvas state ready to draw a large font. You may have set it at the start and then don't intend to use it again, but while that font sits there ready to maybe drawn, it is using valuable RAM