parallelism

rust
use rayon::prelude::*;

fn main() {
    let numbers: Vec<_> = (0..1000).collect();

    let sum: i32 = numbers

Rayon for data parallelism with par_iter

rust parallelism rayon
by Marcus Chen 1 tab
javascript
const { Worker, MessageChannel } = require('node:worker_threads');
const path = require('node:path');

class WorkerPool {
  constructor(size) {
    this.workers = [];

Fan Out CPU Work to Node.js worker_threads and Merge Results via MessageChannel

nodejs worker-threads concurrency
by codesnips 3 tabs
ruby
# Basic Ractor usage
ractor = Ractor.new do
  # This runs in parallel, isolated from main thread
  result = heavy_computation
  result
end

Concurrent Ruby with Ractors and Async

ruby concurrency parallelism
by Sarah Mitchell 2 tabs
rust
#[derive(Debug, Clone)]
pub struct Order {
    pub id: u64,
    pub amount_cents: i64,
    pub currency: [u8; 3],
}

Partition a Slice of Orders into Shards for Parallel Processing with Rayon

rust rayon parallelism
by codesnips 2 tabs
java
public class ProductAggregator implements AutoCloseable {

    private final RemoteServices services;
    private final ExecutorService pool = Executors.newFixedThreadPool(8);

    public ProductAggregator(RemoteServices services) {

Coordinate Parallel Remote Lookups With CompletableFuture in Java

java completablefuture concurrency
by codesnips 3 tabs
ruby
module BoundedFanOut
  Result = Struct.new(:value, :error) do
    def ok?
      error.nil?
    end
  end

Parallelize Independent External Calls (in a bounded way)

concurrency threads http
by codesnips 3 tabs
rust
use std::collections::HashMap;
use std::path::PathBuf;

use walkdir::WalkDir;

pub fn group_by_size(root: &str) -> HashMap<u64, Vec<PathBuf>> {

Detect Duplicate Files with Parallel Blake3 Checksums in Rust

rust checksums blake3
by codesnips 4 tabs
rust
mod chunker;mod parallel_hash;

use parallel_hash::{hash_buffer, root_hash};

const CHUNK_SIZE: usize = 64 * 1024;

Content-Defined Chunking With Parallel BLAKE3 Hashing Using Rayon

rust rayon parallelism
by codesnips 3 tabs