Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 934657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:02:16+00:00 2026-05-15T21:02:16+00:00

My impl of fillRect much (> 3 times) slower than context2d.fillRect. How I can

  • 0

My impl of fillRect much (> 3 times) slower than context2d.fillRect. How I can optimize my code or why builtin fillRect faster (some app acceleration?)?

My impl:

  __fillRect : function (data, x, y)//, r, g, b)
  {
    var w = this.__width * 4;
    var idx = x * 4+ y * w;
    var idx_1 = idx + 4;
    var idx_2 = idx + 8;
    var idx_3 = idx + w;
    var idx_4 = idx_3 + 4;
    var idx_5 = idx_3 + 8;
    var idx_6 = idx_3 + w;
    var idx_7 = idx_6 + 4;
    var idx_8 = idx_6 + 8;

    function __setPixelIdx (idx)
    {
      data[idx + 0] = 200;
      data[idx + 1] = 0;
      data[idx + 2] = 0;
      data[idx + 3] = 255;
    }

    __setPixelIdx (idx);
    __setPixelIdx (idx_1);
    __setPixelIdx (idx_2);
    __setPixelIdx (idx_3);
    __setPixelIdx (idx_4);
    __setPixelIdx (idx_5);
    __setPixelIdx (idx_6);
    __setPixelIdx (idx_7);
    __setPixelIdx (idx_8);

  },
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:02:17+00:00Added an answer on May 15, 2026 at 9:02 pm

    Your implementation is slower for a few reasons:

    • You are writing to an array and then copying and converting that into the canvas framebuffer.
    • context2d.fillRect is running native code, not interpreted or JIT compiled JavaScript.
    • context2d can potentially use graphics hardware to draw
    • You are writing single bytes at a time whereas even an unaccelerated native library could write whole int32 pixel values

    My advice is use the native fillRect method unless you have a very good reason not too (e.g. doing your own shading or masking). You will not get anywhere near the speed of the library function.

    Calling __setPixelIdx instead of doing the data accessing in the main __fillRect function probably isn’t helping much.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Hibernate's JPA impl to model some tables. I'm having trouble mapping a
In an Android app, I am using one static instance of org.apache.http.impl.client.DefaultHttpClient and sharing
I'd like to: <unjar src=lib/mst-service-impl*.zip but I can't put an asterisk in there. It
I thought SLF4J would load org.slf4j.impl.StaticLoggerBinder via reflection but looking at the code in
I can't figure out why I get this error : /usr/local/include/boost/asio/impl/read.hpp: In member function
How can I get reference to the task my code is executed within? ISomeInterface
I'm trying to add jsf-api and jsf-impl dependencies to a project, and can't find
My code write a XML file with the LSSerializer class : DOMImplementation impl =
Can anyone see any problems with this Producer/Consumer unique keyed buffer impl? The idea
The classes: public interface Inter { ...some methods... } public class Impl implements Inter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.