$ show zupat/related_post_gen
This repository is a benchmark suite for comparing the performance of different programming languages in solving the 'related posts' problem: given a list of posts with tags, compute the top 5 related posts for each post based on shared tags. The architecture consists of language-specific implementations (over 50 languages) that all follow the same algorithm: build a tag-to-post-index map, then for each post count shared tags via that map, and select the top 5 posts using a custom priority queue. The repository includes Dockerfiles for each language, helper scripts for running benchmarks, and a workflow that automates execution across multiple post counts (5k, 20k, 60k) and updates a README with results. The code demonstrates strong engineering practices: consistent algorithm across implementations, use of language-specific optimizations (e.g., SIMD, custom hash maps, parallelization), and careful attention to performance measurement (excluding I/O).
The LLM identified 3 files worth highlighting for reuse:
The Python implementation demonstrates the core algorithm efficiently: it uses defaultdict to build a tagβpost index map, then for each post resets a tagged_post_count array, increments counts via the map, and uses a flattened top5 array (count, index pairs) with a custom priority queue to find top 5 related posts. This pattern is replicated across all language implementations, showing a consistent, reusable approach to the problem.
The Rust implementation showcases advanced performance techniques: it uses hashbrown for hash maps, aligned_vec for cache-line aligned data structures, processes tagged_post_count in chunks to leverage SIMD, and zeroes chunks while still in L1 cache. This represents a highly optimized, reusable pattern for frequency counting and top-k selection that could be extracted for similar problems.
The Dart implementation introduces a TaggedPosts class to help the AOT compiler infer types, preallocates and reuses tagged_post_count and top5 arrays, and uses a flattened list for efficient top-k selection without unnecessary allocations. This demonstrates a reusable pattern for optimizing Dart AOT compilation while maintaining algorithmic clarity.