fastcache
by
VictoriaMetrics

Description: Fast thread-safe inmemory cache for big number of entries in Go. Minimizes GC overhead

View on GitHub ↗

Summary Information

Updated 36 minutes ago
Added to GitGenius on October 22nd, 2023
Created on November 22nd, 2018
Open Issues & Pull Requests: 47 (+0)
Number of forks: 194
Total Stargazers: 2,372 (+0)
Total Subscribers: 35 (+0)

Issue Activity (beta)

Open issues: 36
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 1,776 days
Stale 30+ days: 36
Stale 90+ days: 35

Recent activity

Opened in 7 days: 0
Closed in 7 days: 0
Comments in 7 days: 0
Events in 7 days: 0

Top labels

  • question (14)
  • enhancement (6)
  • bug (1)

Most active issues this week

No issue events were indexed in the last 7 days.

Repository Insights (GitGenius)

Median issue/PR response: 1340.3 days
Mean response time: 1115.6 days
90th percentile: 2023.4 days
Tracked items: 8

Most active contributors

Detailed Description

Fastcache is a high-performance, thread-safe in-memory cache library written in Go, specifically designed to handle large numbers of entries while minimizing garbage collection overhead. The project was extracted from VictoriaMetrics, a time-series database system, and addresses a critical performance challenge in Go applications that need to cache substantial amounts of data without incurring excessive GC costs.

The core architecture employs a bucket-based design where the cache consists of many buckets, each protected by its own lock. This approach enables performance to scale effectively across multi-core CPUs since different cores can concurrently access distinct buckets without contention. Within each bucket, the cache maintains a hash map that tracks key positions and uses 64KB-sized byte slices, called chunks, to store encoded key-value entries. This chunking strategy significantly reduces memory fragmentation and pointer overhead compared to traditional Go maps. A 64GB cache using fastcache would contain approximately one million pointers, whereas an equivalent map[string][]byte would require around one billion pointers for short keys and values, creating substantial GC pressure.

Fastcache implements automatic eviction of old entries when the cache reaches its configured maximum size, eliminating the need for manual memory management. The library supports persistence through SaveToFile and LoadFromFile operations, allowing caches to be serialized and restored. It also works on Google AppEngine, making it suitable for cloud-deployed applications. The API is intentionally simple and designed for zero-allocation usage patterns, avoiding unnecessary memory allocations during cache operations.

The library does have specific constraints. Keys and values must be byte slices, requiring users to marshal other data types before storage. Entries exceeding 64KB in size must use a distinct API designed for large values. Notably, fastcache does not implement automatic cache expiration; entries are evicted only when the cache size overflows. Users can implement expiration semantics by marshaling deadlines into cached values and validating them upon retrieval.

Benchmark comparisons demonstrate that fastcache outperforms BigCache, standard Go maps, and sync.Map across various workloads, particularly on insert-heavy operations. The performance advantage stems from the bucket-locking strategy and the reduced pointer density achieved through chunked storage.

According to GitGenius activity tracking, the repository shows median issue and pull request response latency of approximately 32,167 hours with a mean of 26,775 hours across tracked items. The most active contributor tracked is f41gh7 with seven events, followed by ZMbiubiubiu and askformydream with one event each. The repository maintains connections with other significant Go projects including golang/go, tursodatabase/turso, and victoriametrics/victoriametrics through overlapping contributors.

The design philosophy prioritizes simplicity and performance over feature richness. The developers explicitly chose not to implement advanced features like thundering herd protection or eviction callbacks, reasoning that such additions would complicate the codebase and reduce performance. Instead, users can copy and extend the source code to add custom functionality as needed.

fastcache
by
VictoriaMetricsVictoriaMetrics/fastcache

Repository Details

Fetching additional details & charts...