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 5963895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:20:05+00:00 2026-05-22T19:20:05+00:00

I would like to know which situation has more overhead: 1) Case 1: 5

  • 0

I would like to know which situation has more “overhead”:

1) Case 1: 5 million objects sharing 30 functions. everytime a function is called, there is an overhead because it is necessary to do f.call(instance, arg1, arg2, etc)

 //example code
function makeObject()
{
  return { method1:func1,
           method2:func2,
           ...
           method30:func30 };
}

2) Case 2: 5 million objects with 30 functions each (= 150 million individual function instances). Everytime a function is called, there’s no “routing-overhead” but of course at the sacrifice of having more instances

//example code
function makeObject()
{
  return { method1:func1.bind(asd),
           method2:func2.bind(asd),
           ...
           method30:func30.bind(asd) };
}

5 million is just a number my fingers typed out while my brain is still figuring out a nice number for an example.

Basically I want to know generally should we share functions whenever possible or create new ones?

(You can assume that i will never use the eval function anywhere in the entire page)

  • 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-22T19:20:06+00:00Added an answer on May 22, 2026 at 7:20 pm

    Since almost all modern browsers optimize the prototype- and scopeschain lookup, you definitely should go for the sharing of methods.

    The optimization technique described in simple words, is a kind of hash lookup table which the javascript engine uses to access propertys/methods from out of scope variables. So there is very little overhead in comparision to a classic scope chain lookup where the engine has to crawl through each parent scopes variable-/activation object.

    This optimized lookup will only fail, if there is some kind of direct eval‘ed code. Since an eval can change the propertys from a context, an engine must fallback to a classic lookup algorythm (which is kind of slow).

    However, 5m objects are kind of unreal for Javascript-engines and I hope that those numbers are just examples. In a real world scenario, 5m objects calling n number of functions would create a stack overflow and “too long running script” errors everywhere around.

    Alone the parsing time for 150 million functions will be disgraceful.

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

Sidebar

Related Questions

I would like to know how to dispose objects correctly in the following situation.
I would like to know which dependency described in my pom.xml brings a transitive
I would like to know which one is the best material that I can
i would like to know , how ill know which inlines forms was edited?
I've got an executable file, and I would like to know which version(s) of
I would like to know the procedure which will give the out put about
I would like to know where can I find the code which eclipse uses
I am creating an iphone performance app in which I would like to know
There is a situation that I am faced with which seems like it has
I would like to know if the module pattern or Constructor/protoType pattern is more

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.