I have this repository :

@Singleton
class ImageRepository @Inject constructor(
    @ApplicationContext private val context: Context,
) {


    // Initialize Realm instance
    private val realm: Realm = App.realm

    // Flow of processed images from Realm
    val processedImages: Flow<List<ImageLabel>> = realm
        .query<RealMImageLabel>()
        .asFlow()
        .map { realmResults ->
            realmResults.list.map { it.toImageLabel() }
        }

    // Function to add a processed image to Realm
    suspend fun addProcessedImage(imageLabel: ImageLabel) = withContext(Dispatchers.IO) {
        realm.write {
            copyToRealm(imageLabel.toRealmImageLabel(), updatePolicy = UpdatePolicy.ALL)
        }
    }

    // Flow of all images (processed and in progress)
    val allImages: Flow<List<Media>> = flow {
        // This assumes queryImages provides a Flow
        emit(queryImages(context))
    }


    // Clean up resources when the repository is no longer needed
    fun close() {
        realm.close()
    }
}

this viewmodel:

class ImagesViewmodel
@Inject constructor(
    @ApplicationContext val context: Context,
    private val repository: ImageRepository,
) : ScreenModel {
    // Flow for processed images
    val processedImages: StateFlow<List<ImageLabel>> = repository.processedImages
        .stateIn(screenModelScope, SharingStarted.Lazily, emptyList())

    // Flow for in-progress images
    // Flow for all images
    val allImages: StateFlow<List<Media>> = combine(
        repository.allImages.distinctUntilChanged(),
        processedImages
    ) { allImages, processedIds ->
        val processedimageIds = processedIds.map { it.imageId }
        allImages.sortedBy { it.time }.map { media ->
            media.copy(
                processed = media.id in
                        processedimageIds)
        }
    }
        .distinctUntilChanged()
        .stateIn(screenModelScope, SharingStarted.Lazily, emptyList())

and this is my screen:
    @Composable
    override fun Content() {
        val navigator = LocalNavigator.currentOrThrow
        val viewModel = navigator.getNavigatorScreenModel<ImagesViewmodel>()
        val allImages by viewModel.allImages.collectAsState(emptyList())
        val processedImages by viewModel.processedImages.collectAsState(emptyList())
        val activityEvents = LocalActivityEventsProvider.current
        activityEvents?.events?.collectAsEffect(key = activityEvents.events) {
            when (it) {
                ActivityEvents.ActivityTrigger.StartSync -> {
                    viewModel.startImageProcessingService()
                }
            }
        }
        LaunchedEffect(
            allImages
        ) {
            //log it
            Log.wtf("HomeScreen", "Processed Images: $allImages")
        }

        Column {
            //lazy grid that contains items for processed and unprocessed images
            LazyVerticalGrid(
                columns = GridCells.Fixed(3),
                modifier = Modifier
                    .fillMaxSize()
                    .padding(horizontal = 20.dp)
                    .background(Color.Blue),
                horizontalArrangement = Arrangement.spacedBy(4.dp)
            ) {
                item(span = {
                    GridItemSpan(maxLineSpan)
                }) {
                    Text(text = "All Images")
                }
                items(processedImages){

                }
                items(allImages) { image ->
                    ImageGridItem(
                        imageUri = image.uri,
                        processed = image.processed
                    )


                }

            }

        }

    }
I process images in a service 100 by 100:
by calling this function:
    private suspend fun processImages() {
        // Fetch all images
        val allImages = repository.allImages.first() // Adjust based on actual implementation
        Log.wtf("ImageProcessingService", "All Images: $allImages")
        // Filter unprocessed images
        val processedIds =
            repository.processedImages.map { it.map { imageLabel -> imageLabel.imageId } }.first()
        val unprocessedImages = allImages.filter { it.id !in processedIds }
        val time = measureTime {

            unprocessedImages.chunked(100).forEach { batch ->
                val otherTime = measureTime {
                    batch.asFlow()
                        .mapNotNull { media ->
                            try {
                                val imageLabel =
                                    detectionManager.detect(this@ImageProcessingService, media)
                                imageLabel

                            } catch (e: Exception) {
                                // Handle exceptions
                                null
                            }
                        }
                        .buffer()
                        .collect { imageLabel ->
                            repository.addProcessedImage(imageLabel)
                        }

                }
                Log.wtf("imageProcessing_batch", "time is $otherTime")
            }
        }
        // Process images in batches of 100
        // Stop the service after processing
        Log.wtf("ImageProcessingService", "Processing of ${unprocessedImages.size} took $time")
        stopSelf()
    }


the problem is every time an image is processed the allimages flow in the viewmodel keeps emitting new values when the difference is there is a boolean in the media class
that marks the media as processed or not which just changes :

@Immutable
data class Media(
    val id: Long,
    val uri: Uri,
    val time: Long,
    val processed: Boolean = false,
) {
    suspend fun toInputImage(context: Context): InputImage? {
        return try {
            withContext(Dispatchers.IO) { InputImage.fromFilePath(context, uri) }
        } catch (e: Exception) {
            Log.w("Media", "Failed to create InputImage from $uri", e)
            null
        }


    }
}


how do I get better ui performance