What is the maximum size allowed for creating a Set in JavaScript?

I am currently developing a tool to remove geometry from a 3D model within a web browser.

During a specific stage of the removal process, I take an array containing indexes and convert it into a Set to eliminate any duplicate indexes.

function TransformArrayIntoSet(array){
    return new Set(array);
}

This function initially performed well for most models. To enhance the efficiency of the deletion process, I aimed to avoid solutions that involved using .indexOf.

However, when attempting to delete elements from a large model, such as an array with approximately 15,000,000 entries, I encountered the following error in the browser console:

Uncaught (in promise) RangeError: Set maximum size exceeded

I would like to understand what limits exist when creating a Set. Is this limitation determined by the Browser or the hardware running the Browser? Is there a method to determine this limit? Perhaps if I knew the size constraint of a Set, I could divide the array into multiple Sets and proceed accordingly?

Answer №1

The group of objects in a Set is referred to as a "List" in the specification, and there is no specified limit on the size of a List. More information can be found here.

These sequences can vary in length.

The size of Set lists is also not specified. (1, 2)

  1. Set set.[[SetData]] to a new empty List.

Therefore, it is left to be defined by the implementation.

Does this depend on the browser being used? Or is it influenced by the computer's specifications?

This will vary based on the JavaScript engine utilized by the browser (e.g. V8, SpiderMonkey, JavaScriptCore).

Is there a method to determine this limit?

Simply keep adding items to a Set until it reaches its limit and throws an error.

const getSetSizeLimit = () => {
  let i = 0;
  const set = new Set();
  while (true) {
    try {
      set.add(i);
    } catch(e) {
      return i;
    }
    i++;
  }
  return i;
};
console.log(getSetSizeLimit());

In my experience with Windows-Chrome, the limit appears to be 16777216, equivalent to 2 ** 24.

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

Restrict the Three.js Raycaster to a designated section within the HTML without using offsets

As I dive into using Three.js and the Raycaster for object picking, my HTML structure consists of a Navigation Bar in the head section and the rendering area in the body section. However, I encountered an issue where there was an offset in the Raycaster d ...

Sending a document to a Node.js server using Sails.js

I utilized sails.js on node to set up a server with an end-point for uploading files, following the guidance provided on this page. Below is the complete code snippet: req.file('file').upload({ maxBytes: 10000000, dirname: './my-dir&ap ...

Stop Opera browser from enhancing HTML5 fields

Currently, I am utilizing numerous inputs with HTML5 types (like 'date' or 'time') through the jQuery Tools library. Certain browsers, such as Opera, have the capability to automatically identify these types and convert them accordingly ...

Executing the GetDoc function multiple times in a React application

Utilizing Firebase for Authentication & Storage and incorporating useContext from react to encase my application with an authentication layer. After retrieving the user from the authentication layer, I proceed to fetch the user's details from Firesto ...

What is the process for embedding JQuery within the <body> tags in Joomla 3.1?

I inserted the following code into my default.php file in Joomla 3.1. <?php JHtml::_('jquery.framework'); JFactory::getDocument()->addScript(JURI::root().'template/mytemplate/js/jquery.min.js'); ?> However, this code only pl ...

Experiencing a scroll problem in the latest version of Google Chrome for Android while using ReactJS? The issue seems to have migrated from the earlier version 99.xxxxxx to

Previously, my website was functioning perfectly in full screen mode. However, after updating Chrome on Android to the latest version (116.xxxxxx....), I noticed that it is now displaying a scrolling behavior that was not present in the earlier version (99 ...

Animated Debugging with Node.js

Encountering an issue with code that runs smoothly on other devices but seems to be laptop-specific. Even a simple "hello world" application is only displaying a debug image instead of the expected output. repository folder> node app.js Express Server ...

Leveraging the push method within AngularJS

Hello, I am currently working on setting up an eCommerce shop using Angular. Below is the code snippet I am using: var shopApp = angular.module('shopApp', ["slugifier"], function() {}); controllers.productController = function($scope,FetchFa ...

Utilize a JSON object with ChartJS for data visualization

Recently, I've been working with a REST API that returns historical data in the following format: { "2021-6-12": 2, "2021-6-13": 3, "2021-6-14" :1 } This data represents the count of measurements taken on each date ...

Using a checkbox to enlarge a table

<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script> <script type='text/javascript'> $(window).load(function () { $('.varx').click(function () { ...

Outputting messages to a component with React

I'm attempting to create a component similar to a console where messages are displayed one after the other instead of replacing the old message. My goal is to have a component where I can input strings, like in a chatbox, using different parts of my ...

JS client-side form validation involves communicating with the server to verify user input

I currently have an HTML form that is being validated on the client side. Below is a snippet of the code: <form id='myForm' onsubmit='return myFormValidation()'> ... </form> Now, I want to incorporate server-side valida ...

Adjust the zoom level of a webpage while printing using javascript

Hello, I have been trying to print in Landscape mode using JavaScript, but since there was no standard code available, I decided to rotate the page div 90 degrees to achieve the landscape orientation. However, this has proven to be unhelpful as it results ...

The .remove() method is ineffective when used within an Ajax success function

I am facing an issue with removing HTML divs generated using jinja2 as shown below: {% for student in students %} <div class="item" id="{{ student.id }}_div"> <div class="right floated content"> <div class="negative ui button compa ...

Having trouble reaching the JSON object beyond the scope of the AJAX success function

Having trouble accessing a JSON object outside of the AJAX success scope? Need to find a solution to this problem? Look no further! This is what was initially attempted: An approach that works but may not be suitable for your needs: $(' ...

Tips for altering the checked status of a radio input in a React component

I'm working with input type radio buttons const AnswerOptions = (props) => ( <> <input type="radio" id="something" ...

What is the maximum storage capacity for variables on a NodeJS/ExpressJS server when handling multiple users?

As I delve into the node server code, I find myself pondering on the idea of storing temporary data - objects and arrays - within variables. These variables are housed in the client variable of a socket and are purged when connection with the client is l ...

Is there a way to automatically execute a Greasemonkey script when the page is updated using ajax?

Here is the script I am using: // ==UserScript== // @name sample // @include http://xxx* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js // ==/UserScript== var findElement = function(elements, text) { for (var i = 0; ...

Expand the image to fill the entirety of the viewing area

Check out my development website. Whenever you click on an image, a photo slider (using photoswipe) pops up. Is there any way to have the image fill the entire viewport? I attempted using height: 100vh, width: auto, but it didn't work. https://i.ssta ...

What is the reason AJAX does not prevent page from refreshing?

Can anyone offer some guidance on using AJAX in Django? I'm attempting to create a basic form with two inputs and send the data to my Python backend without refreshing the page. Below is the AJAX code I am using: <script type="text/javascript& ...