# Jparepository saveAll() drives to bad performance for indexed object

**URL:** https://discourse.hibernate.org/t/jparepository-saveall-drives-to-bad-performance-for-indexed-object/10646
**Category:** Hibernate Search
**Created:** [November 21, 2024, 1:26pm UTC](https://discourse.hibernate.org/t/jparepository-saveall-drives-to-bad-performance-for-indexed-object/10646 "2024-11-21T13:26:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Tony](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/tony/32/2448_2.png) [@Tony](https://discourse.hibernate.org/u/Tony)
#### Post date: [November 21, 2024, 1:26pm UTC](https://discourse.hibernate.org/t/jparepository-saveall-drives-to-bad-performance-for-indexed-object/10646/1 "2024-11-21T13:26:14Z")

</div>

Hi. Using hibernate search 6.1.8 and calling JpaRepository, repository.saveAll(list) where the list contains \>20k records i notice that saveAll has too bad performance because it updates the indexes of my object as well.  
Is there any way to improve the performance somehow ?

```auto
@Getter
@Setter
@RequiredArgsConstructor
@Entity
@Indexed(index = "idx_object")
@DynamicUpdate
@Table(name = "object")
public class Object extends BaseEntity {
...
}

```

Thank you.

---

<div class="post-metadata">

### Author: ![mbekhta](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbekhta/32/2044_2.png) [@mbekhta](https://discourse.hibernate.org/u/mbekhta)
#### Post date: [November 21, 2024, 5:18pm UTC](https://discourse.hibernate.org/t/jparepository-saveall-drives-to-bad-performance-for-indexed-object/10646/2 "2024-11-21T17:18:50Z")

</div>

Hey Tony,

> [@Tony](#):
>
> where the list contains \>20k records

Persisting 20k records at a time is already problematic, and adding indexing on top of that doesn’t help. Depending on your use case, you could try:

- doing this in smaller batches, see [Hibernate Search 7.2.1.Final: Reference Documentation](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-indexing-manual-indexingplan-process-execute) ( Example 159/ Example 160).
- disable the listener-triggered indexing (either for this update or entirely) and use mass indexer to index your records. [Hibernate Search 7.2.1.Final: Reference Documentation](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#indexing-plan-filter) / [Hibernate Search 7.2.1.Final: Reference Documentation](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#indexing-automatic-configuration)
- use outbox-polling to offload indexing to a background process: [Hibernate Search 7.2.1.Final: Reference Documentation](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#coordination-outbox-polling)

But… indexing of 20k records will have to happen somewhere at some point, be it right away, later or in chunks. Hence, I’d suggest looking into how to reduce the number of entities updated/created, and if it really has to be 20k at a time … then the expectations just have to be adjusted 😃 it’s going to take time …
