Do not create too many rayon tasks when processing the settings

This commit is contained in:
Kerollmops
2025-01-29 17:02:06 +01:00
parent e0f446e4d3
commit 4b488b2baf
3 changed files with 36 additions and 24 deletions

View File

@@ -98,6 +98,9 @@ impl Embedder {
text_chunks: Vec<Vec<String>>, text_chunks: Vec<Vec<String>>,
threads: &ThreadPoolNoAbort, threads: &ThreadPoolNoAbort,
) -> Result<Vec<Vec<Embedding>>, EmbedError> { ) -> Result<Vec<Vec<Embedding>>, EmbedError> {
if threads.active_operations() >= REQUEST_PARALLELISM {
text_chunks.into_iter().map(move |chunk| self.embed(&chunk, None)).collect()
} else {
threads threads
.install(move || { .install(move || {
text_chunks.into_par_iter().map(move |chunk| self.embed(&chunk, None)).collect() text_chunks.into_par_iter().map(move |chunk| self.embed(&chunk, None)).collect()
@@ -107,6 +110,7 @@ impl Embedder {
fault: FaultSource::Bug, fault: FaultSource::Bug,
})? })?
} }
}
pub(crate) fn embed_chunks_ref( pub(crate) fn embed_chunks_ref(
&self, &self,

View File

@@ -255,6 +255,9 @@ impl Embedder {
text_chunks: Vec<Vec<String>>, text_chunks: Vec<Vec<String>>,
threads: &ThreadPoolNoAbort, threads: &ThreadPoolNoAbort,
) -> Result<Vec<Vec<Embedding>>, EmbedError> { ) -> Result<Vec<Vec<Embedding>>, EmbedError> {
if threads.active_operations() >= REQUEST_PARALLELISM {
text_chunks.into_iter().map(move |chunk| self.embed(&chunk, None)).collect()
} else {
threads threads
.install(move || { .install(move || {
text_chunks.into_par_iter().map(move |chunk| self.embed(&chunk, None)).collect() text_chunks.into_par_iter().map(move |chunk| self.embed(&chunk, None)).collect()
@@ -264,6 +267,7 @@ impl Embedder {
fault: FaultSource::Bug, fault: FaultSource::Bug,
})? })?
} }
}
pub(crate) fn embed_chunks_ref( pub(crate) fn embed_chunks_ref(
&self, &self,

View File

@@ -188,6 +188,9 @@ impl Embedder {
text_chunks: Vec<Vec<String>>, text_chunks: Vec<Vec<String>>,
threads: &ThreadPoolNoAbort, threads: &ThreadPoolNoAbort,
) -> Result<Vec<Vec<Embedding>>, EmbedError> { ) -> Result<Vec<Vec<Embedding>>, EmbedError> {
if threads.active_operations() >= REQUEST_PARALLELISM {
text_chunks.into_iter().map(move |chunk| self.embed(chunk, None)).collect()
} else {
threads threads
.install(move || { .install(move || {
text_chunks.into_par_iter().map(move |chunk| self.embed(chunk, None)).collect() text_chunks.into_par_iter().map(move |chunk| self.embed(chunk, None)).collect()
@@ -197,6 +200,7 @@ impl Embedder {
fault: FaultSource::Bug, fault: FaultSource::Bug,
})? })?
} }
}
pub(crate) fn embed_chunks_ref( pub(crate) fn embed_chunks_ref(
&self, &self,