The challenges with optimizing performance in VueJS v-for loops

I am working on a small app that helps track coin portfolios. However, I am facing an issue when making about 2000 data calls from the API. When trying to list them using v-for, my app starts freezing after around 100 calls. It takes approximately 10 seconds to get and list the data, and when I attempt to search for something, the app freezes, resulting in a poor user experience.

Currently, my app is only able to receive 100 data objects without any problems. Below is a snippet of the code I am using:

async created() {
    this.loaded = false;

    try {
      const response = await fetch(
        'https://api2.binance.com/api/v3/ticker/24hr'
      );
      const data = await response.json();
      // Get first 100 of data
      data.slice(0, 100).forEach(element => {
        this.chartData.symbols = [...this.chartData.symbols, element.symbol];
        this.chartData.price = [...this.chartData.price, +element.lastPrice];
      });

      this.loaded = true;
    } catch (e) {
      console.error(e);
    } 

If you would like to take a closer look at the code, feel free to visit my GitHub repository here.

Answer №1

I have addressed a similar issue in another thread: (last 2 responses)

In summary, it seems that you are using the .slice function, but still loading the entire collection of objects on your frontend.


The API documentation for Binance is somewhat lacking, as I couldn't find a direct reference to any specific endpoint. Therefore, I have included a screenshot of the relevant endpoint:

https://i.sstatic.net/8UQBx.png

You may be able to locate it by utilizing the search feature.

By default, accessing

https://api2.binance.com/api/v3/ticker/24hr
will provide you with various fields, including

[
  'symbol',
  'priceChange',
  'priceChangePercent',
  'weightedAvgPrice',
  'prevClosePrice',
  'lastPrice',
  'lastQty',
  'bidPrice',
  'bidQty',
  'askPrice',
  'askQty',
  'openPrice',
  'highPrice',
  'lowPrice',
  'volume',
  'quoteVolume',
  'openTime',
  'closeTime',
  'firstId',
  'lastId',
  'count',
]

If you append MINI like so

https://api2.binance.com/api/v3/ticker/24hr?type=MINI
, you can narrow down the received fields to:

[
  'symbol',
  'openPrice',
  'highPrice',
  'lowPrice',
  'lastPrice',
  'volume',
  'quoteVolume',
  'openTime',
  'closeTime',
  'firstId',
  'lastId',
  'count',
]

You also have the option to specify the tokens you wish to retrieve, which could be worth considering.


Furthermore, I did not come across any information regarding pagination within the API. It appears that they do not prioritize developer experience and expect users to handle it themselves.
Therefore, you might want to consider utilizing a backend middleware, a serverless function, or another solution as a proxy to offload this task from your client-side application.

No shortcuts here, as previously explained in my responses.

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

The search box output will be the same as the JSON result

I have a server in Node.js that is able to read and process a JSON file containing various data, including unique user IDs. I have incorporated a search box into my HTML page, and I am seeking assistance with creating a jQuery method (which will require AJ ...

I recently created a "dist" folder through Babel. Is it possible to integrate the files within this folder directly into a fresh React project?

I have a React library that is available on npm. My process for publishing it involves the following steps: To begin, I create a folder called dist using Babel by executing this command- babel ./src -d ./dist Next, I upload the resulting dist directory ...

Retrieve JSON data from an object using the Amplify Storage feature

I recently retrieved data from an object in an S3 Bucket using Amplify. export function amplify() { let key = "68a92d44-f25a-4bd8-9543-cc95369ae9a0"; return Storage.get(key + ".json", { download: true }) .then(function(result) { return ...

What is the best way to track and display the window.scrollY value in the console using Next.js

Unfortunately, my ScrollToTop component is not functioning correctly within my app. I have exhausted all possible debugging methods but am still unable to determine why the scrollY value is not being logged as expected. Even after moving the snippet to a ...

"What could be the reason for web3.eth.getAccounts() method returning an empty array when used with console.log

Upon executing web3.eth.getAccounts().then(console.log);, I encountered an empty array and also received a warning stating ./node_modules/web3-eth-accounts/src/scrypt.js Critical dependency: the request of a dependency is an expression. The project began w ...

Material Style Minimal - There is a slight space between the text field and the colored line at the bottom

Having a problem with Material Design Lite text field where there is a small gap between the bottom colored line and the gray starting line. Every MDL text field example I try on my page shows the same issue. What could be causing this locally? My frontend ...

Zebra lines overlooking unseen details

Imagine having a table where rows can be dynamically assigned classes such as .hidden, which hide those rows using CSS. The rows are styled with alternating colors, like this: tr:nth-child(even) { background-color: $light-grey; } But here's the ...

Utilizing JSON Data for Dynamically Displaying Database Objects on a Google Map

After carefully reviewing the information provided in the initial responses and working on implementation, I am updating this question. I am currently utilizing the Google Maps API to incorporate a map into my Ruby on Rails website. Within my markets mode ...

Troubleshooting Layout Transition Problems in Nuxt 3

Encountering a challenge with route transitions while selectively disabling layouts on specific pages. Within the app.vue, there's a <NuxtPage /> wrapped in default <NuxtLayout /> containing header and footer elements. The 'About&apos ...

Exploring object key-value pairs using the 'for in' loop in JavaScript

Embarking on a project to develop a quiz in javascript, I am starting with an array that holds the questions as anonymous objects. var allQuestions = [{ "question": "Who was Luke's wingman in the battle at Hoth?", "choices": ["Dak", "Biggs", "Wedge", ...

What is the reason for the reconnect function not activating when manually reconnecting in Socket.IO?

After disconnecting the client from the node server using socket.disconnect(true);, I manually re-establish the connection on the client side with socket.open(). The issue arises when triggering socket.open(); the socket.on('reconnect', (attempt ...

Checking if the group of radio buttons has been selected using JQUERY

Need help with validating a group of radio buttons. If none are checked, display an error message in the span element to prompt users to select an option. The strange issue I am facing is that the validation code works only when placed below the radio butt ...

Verify whether the element is currently visible within an iframe on the same domain

My goal with jQuery is to determine element visibility on a webpage. In my website, there is an iframe within one of the pages. Typically, I check for element visibility using the following code: if($('.tabContentContainer').is(':visible& ...

v-treeview component triggering method execution twice upon input

I'm facing an issue with my Vue component that contains a treeview. Upon selecting a node, the goal is to update an array and display the checkbox as selected. However, I'm encountering a problem where if I select elements from one folder in the ...

Tips for preserving state data post-page refresh in Nuxt3

When refreshing the page in Nuxt3, I am experiencing data loss in the state. Despite using localStorage and sessionStorage, the data is still being lost. Can anyone advise on how to maintain state data after a page refresh? Here is a snippet of my sourc ...

Issue with page refreshing not functioning on localhost in Rails and AngularJS collaboration

I recently encountered a strange issue while working on my Rails 4.2 + AngularJS 1.5 project. Whenever I attempt to refresh (F5) the main web-page, there's about a 9 out of 10 chance that the refresh doesn't happen correctly. In these cases, all ...

Creating pagination using AJAX to fetch data from an API while maintaining the same query parameters

Writing a title for this may be a bit tricky, but I'll try my best. On the webpage located at the /music-maker endpoint, there is a modal that contains an input field. This input field captures user input and sends it to the backend using AJAX. The u ...

Implementing div elements in a carousel of images

I've been working on an image slider that halts scrolling when the mouse hovers over it. However, I'd like to use div tags instead of image tags to create custom shapes within the slider using CSS. Does anyone have any advice on how to achieve th ...

Enable row selection in UI-Grid by clicking on a checkbox with AngularJS

I am a newcomer to angular js and I am looking to have the checkbox automatically selected when clicking on a row to edit that specific cell. I have implemented a cell template to display the checkbox in the UI-grid, but now, when I select a row, the row i ...

angularjs and cakephp working together to handle a request

I've implemented a method in the UsersController to add new users to the database. In the cakephp ctp views, everything seems fine as the request isn't being black-holed and I'm using 'post' for this purpose. However, when I transi ...