# builder.getAll(...) vs fetch?

**URL:** <https://forum.builder.io/t/builder-getall-vs-fetch/6080>\
**Category:** Technical Questions\
**Tags:** api, react, nextjs\
**Created:** [August 6, 2024, 7:50am UTC](https://forum.builder.io/t/builder-getall-vs-fetch/6080 "2024-08-06T07:50:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehan](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Mehan](https://forum.builder.io/u/Mehan)\
**Post date:** [August 6, 2024, 7:50am UTC](https://forum.builder.io/t/builder-getall-vs-fetch/6080/1 "2024-08-06T07:50:33Z")

</div>

Hello,

I have one very specific question.

Here is the case:

Requests made with **builder.getAll(…)** from `'@builder.io/react'` are significantly slower than requests made with plain old **fetch**.

Example:  
The data fetched is a section model (134 entities) in my dev environment (meaning - localhost).

1. With **builder.getAll(…)** takes no less then 5s (sometimes it goes up to 15s), the data is give or take 500 kb in size, and i am using limit + offset, but this does not quite matter, as i am referring to the first request:

**And this is the function with builder.getAll(…)**

```auto
export const getBuilderIoDataAboveTheLimit = async (
  modelId: BuilderIoModelIDs,
  opts?: BuilderIoOptions
) => {
  const _limit = 100;
  let _offset = 0;

  const getData = async () => {
    return await builder.getAll(modelId, {
      options: { enrich: true, offset: _offset, noTargeting: true },
      limit: _limit,
      includeUnpublished: true,
      query: opts?.query,
      sort: opts?.sort,
    });
  };

  const results = await getData();

  while (results.length === _limit + _offset) {
    _offset += _limit;
    const nextResults = await getData();
    results.push(...nextResults);
  }

  return results;

```

1. Now with the fetch is way better.

**This is the function with fetch**

```auto
export const getBuilderIoDataAboveTheLimit = async (
  modelId: BuilderIoModelIDs,
  opts?: BuilderIoOptions
) => {
  const _limit = 100;
  let _offset = 0;

 const query = opts?.query ? `&${opts.query}` : '';
  const sort = opts?.sort ? `&${opts.sort}` : '';

  const getData = async () => {
    return await fetch(
      `https://cdn.builder.io/api/v3/content/${modelId}?apiKey=${APY_KEY}&limit=${_limit}&offset=${_offset}$cachebust=true&includeUnpublished=true${query}${sort}`
    );

  };

  const data = await getData();

  while (data.length === _limit + _offset) {
    _offset += _limit;
    const nextData = await getData();
    data.push(...nextData);
  }

  return data;
};

```

So why is there such a big difference in speed/time and what should i do. Use the plain old **fetch** or do something about **builder.getAll(…)** and use it instead … ?

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [August 6, 2024, 12:19pm UTC](https://forum.builder.io/t/builder-getall-vs-fetch/6080/2 "2024-08-06T12:19:28Z")

</div>

Hello @Mehan,

The significant performance difference you’re observing between using `builder.getAll` and `fetch` is likely due to several factors related to the implementation of the Builder SDK. Here are some key points and recommendations to consider:

1. **Optimize with Fields and Omit:** When using `builder.getAll`, try to limit the fields you are fetching and omit unnecessary ones. This can reduce the payload size and potentially speed up the API response time.

2. **Use Enrich Wisely:** The `enrich` feature can add significant overhead by fetching references and symbols. Only use it if necessary.

3. **Cache Configuration:** Adjust cache settings to balance between data freshness and performance. Using `cacheSeconds` and `staleCacheSeconds` can improve performance by reducing the need to frequently fetch fresh data.

4. **Direct Fetch Approach:** If performance remains an issue, you may continue using the `fetch` API directly as it gives you more control over the request and can be optimized better for your specific needs.
