Repository: LMCache/LMCache
File: lmcache/observability.py (Python)

Code before:

        store_speed = filter_out_zeros(
            [stats.store_speed() for stats in self.store_requests.values()]
        )

        p2p_time_to_transfer = filter_out_zeros(
            [stats.time_to_transfer() for stats in self.p2p_requests.values()]
        )

        p2p_transfer_speed = filter_out_zeros(
            [stats.transfer_speed() for stats in self.p2p_requests.values()]
        )

        request_lookup_hit_rates = filter_out_zeros(
            [
                stats.hit_rate()
                for stats in self.lookup_requests.values()
                if stats.is_finished
            ]
        )

        request_lifespan = filter_out_zeros(
            [
                self.interval_request_cache_lifespan[key]
                for key in self.interval_request_cache_lifespan.keys()
            ]
        )

        ret = LMCacheStats(
            interval_retrieve_requests=self.interval_retrieve_requests,
            interval_store_requests=self.interval_store_requests,
            interval_lookup_requests=self.interval_lookup_requests,
            interval_requested_tokens=self.interval_requested_tokens,
            interval_hit_tokens=self.interval_hit_tokens,
            interval_stored_tokens=self.interval_stored_tokens,
            interval_lookup_tokens=self.interval_lookup_tokens,
            interval_lookup_hits=self.interval_lookup_hits,
            interval_remote_read_requests=self.interval_remote_read_requests,
            interval_remote_read_bytes=self.interval_remote_read_bytes,
            interval_remote_write_requests=self.interval_remote_write_requests,
            interval_remote_write_bytes=self.interval_remote_write_bytes,
            interval_remote_time_to_get=self.interval_remote_time_to_get.copy(),
            interval_remote_time_to_put=self.interval_remote_time_to_put.copy(),
            interval_remote_time_to_get_sync=self.interval_remote_time_to_get_sync.copy(),
            interval_remote_ping_latency=self.interval_remote_ping_latency,
            interval_remote_ping_errors=self.interval_remote_ping_errors,
            interval_remote_ping_success=self.interval_remote_ping_success,
            interval_remote_ping_error_code=self.interval_remote_ping_error_code,
            retrieve_hit_rate=retrieve_hit_rate,
            lookup_hit_rate=lookup_hit_rate,
            interval_local_cpu_evict_count=self.interval_local_cpu_evict_count,

Review comment (performance):
As suggested by gemini review, we can do `self.interval_request_cache_lifespan.values()`. And I guess we don't need `filter_out_zeros` for this, right?

Code after:

        store_speed = filter_out_zeros(
            [stats.store_speed() for stats in self.store_requests.values()]
        )

        p2p_time_to_transfer = filter_out_zeros(
            [stats.time_to_transfer() for stats in self.p2p_requests.values()]
        )

        p2p_transfer_speed = filter_out_zeros(
            [stats.transfer_speed() for stats in self.p2p_requests.values()]
        )

        request_lookup_hit_rates = filter_out_zeros(
            [
                stats.hit_rate()
                for stats in self.lookup_requests.values()
                if stats.is_finished
            ]
        )

        request_lifespan = list(self.interval_request_cache_lifespan.values())

        ret = LMCacheStats(
            interval_retrieve_requests=self.interval_retrieve_requests,
            interval_store_requests=self.interval_store_requests,
            interval_lookup_requests=self.interval_lookup_requests,
            interval_requested_tokens=self.interval_requested_tokens,
            interval_hit_tokens=self.interval_hit_tokens,
            interval_stored_tokens=self.interval_stored_tokens,
            interval_lookup_tokens=self.interval_lookup_tokens,
            interval_lookup_hits=self.interval_lookup_hits,
            interval_remote_read_requests=self.interval_remote_read_requests,
            interval_remote_read_bytes=self.interval_remote_read_bytes,
            interval_remote_write_requests=self.interval_remote_write_requests,
            interval_remote_write_bytes=self.interval_remote_write_bytes,
            interval_remote_time_to_get=self.interval_remote_time_to_get.copy(),
            interval_remote_time_to_put=self.interval_remote_time_to_put.copy(),
            interval_remote_time_to_get_sync=self.interval_remote_time_to_get_sync.copy(),
            interval_remote_ping_latency=self.interval_remote_ping_latency,
            interval_remote_ping_errors=self.interval_remote_ping_errors,
            interval_remote_ping_success=self.interval_remote_ping_success,
            interval_remote_ping_error_code=self.interval_remote_ping_error_code,
            retrieve_hit_rate=retrieve_hit_rate,
            lookup_hit_rate=lookup_hit_rate,
            interval_local_cpu_evict_count=self.interval_local_cpu_evict_count,
            interval_local_cpu_evict_keys_count=self.interval_local_cpu_evict_keys_count,
            interval_local_cpu_evict_failed_count=self.interval_local_cpu_evict_failed_count,
            local_cache_usage_bytes=self.local_cache_usage_bytes,
            remote_cache_usage_bytes=self.remote_cache_usage_bytes,
            local_storage_usage_bytes=self.local_storage_usage_bytes,