u/ILYAMALIK

a 153 times faster esp32 adblocker with 650k+ domains
▲ 92 r/esp32

a 153 times faster esp32 adblocker with 650k+ domains

https://github.com/NikoMalik/esp32-block

A network-wide ad/tracker blocker on a cheap ESP32. It runs as a DNS server for your home: normal domains resolve as usual, ad/tracker/malware domains get answered with 0.0.0.0 so they never load. One small box, every device on the WiFi benefits, no app to install on phones or TVs.

Fork of M-Abozaid/esp32-c3-adblock. This fork targets the classic ESP32 (also builds for C3)

~645,000 domains (ads, trackers, malware, plus Russian lists :) ) live in flash as 40-bit hashes in a bucketed index, memory-mapped and looked up on the device - no PSRAM needed.

The blob is memory-mapped (esp_partition_mmap): the CPU reads it straight through the flash cache like RAM, so steps 2-3 are just a few cache-line reads. That is the main speed win. The earlier design kept the list as a LittleFS file and did one random filesystem read per lookup (~1.2 ms); mmap + buckets dropped that to 8 us 150x faster, ~123k lookups/sec.

u/ILYAMALIK — 7 days ago
▲ 0 r/golang

Strconv2 for golang,zero allocations for hot paths

Fast, zero-allocation integer-string conversion for Go. A focused drop-in for the hot parts of the standard strconv

| Operation | strconv2 | strconv | allocs (strconv2 / strconv) |

|-----------|----------|---------|-----------------------------|

| Format uint64 | 24.8 ns | 49.1 ns (`FormatUint`) | 0 / 1 |

| Format int64 | 27.8 ns | 49.9 ns (`FormatInt`) | 0 / 1 |

| Format uint16 | 10.1 ns | 23.9 ns (`FormatUint`) | 0 / 1 |

| Parse uint64 | 17.7 ns | 51.3 ns (`ParseUint`) | 0 / 0 |

| Parse int64 | 19.3 ns | 55.1 ns (`ParseInt`) | 0 / 0 |

https://github.com/NikoMalik/strconv2

u/ILYAMALIK — 2 months ago
▲ 13 r/rust

A Rust port of Google's Highway SIMD library

Portable SIMD operations with runtime CPU detection and dispatch to the best available target

https://github.com/NikoMalik/highway

C++ Highway vs Rust highway

Side-by-side comparison using a real-world example: SIMD-accelerated Unicode codepoint width lookup (from Ghostty).

C++ (Google Highway)

template <class D, typename T = uint16_t>
int8_t CodepointWidth16(D d, uint16_t input) {
    const size_t N = hn::Lanes(d);
    const hn::Vec<D> input_vec = Set(d, input);

    HWY_ALIGN constexpr T gte_keys[] = { 0x2E3A, 0x3400, 0x4E00, 0xF900, /* ... */ };
    HWY_ALIGN constexpr T lte_keys[] = { 0x2E3A, 0x4DBF, 0x9FFF, 0xFAFF, /* ... */ };

    size_t i = 0;
    for (; i + N <= array_size(lte_keys) && lte_keys[i] != 0; i += N) {
        const hn::Vec<D> lte_vec = hn::Load(d, lte_keys + i);
        const hn::Vec<D> gte_vec = hn::Load(d, gte_keys + i);
        const intptr_t idx = hn::FindFirstTrue(
            d, hn::And(hn::Le(input_vec, lte_vec), hn::Ge(input_vec, gte_vec)));

        if (idx >= 5) return 0;       // zero-width
        else if (idx >= 0) return 2;  // wide
    }

    return 1; // normal width
}

Rust (highway)

use highway::{dispatch, WithSimd, SimdOps};

struct WidthKernel { input: u16 }

impl WithSimd for WidthKernel {
    type Output = i8;

    fn with_simd<S: SimdOps>(self, s: S) -> i8 {
        let n = s.lanes::<u16>();
        let input_vec = unsafe { s.splat::<u16>(self.input) };

        static GTE_KEYS: &[u16] = &[0x2E3A, 0x3400, 0x4E00, 0xF900, /* ... */];
        static LTE_KEYS: &[u16] = &[0x2E3A, 0x4DBF, 0x9FFF, 0xFAFF, /* ... */];

        let mut i = 0;
        while i + n <= LTE_KEYS.len() && LTE_KEYS[i] != 0 {
            unsafe {
                let lte_vec = s.load_u(LTE_KEYS.as_ptr().add(i));
                let gte_vec = s.load_u(GTE_KEYS.as_ptr().add(i));
                let in_range = s.and_mask(s.le(input_vec, lte_vec),
                                          s.ge(input_vec, gte_vec));
                if let Some(idx) = s.find_first_true(in_range) {
                    if idx >= 5 { return 0; }      // zero-width
                    else        { return 2; }       // wide
                }
            }
            i += n;
        }

        1 // normal width
    }
}

let width = dispatch(WidthKernel { input: 0x4E00 }); // CJK Unified Ideograph
assert_eq!(width, 2); // widePortable SIMD operations with runtime CPU detection and dispatch to the best available targethttps://github.com/NikoMalik/highwayC++ Highway vs Rust highwaySide-by-side comparison using a real-world example: SIMD-accelerated Unicode codepoint width lookup (from Ghostty).C++ (Google Highway)template <class D, typename T = uint16_t>
int8_t CodepointWidth16(D d, uint16_t input) {
    const size_t N = hn::Lanes(d);
    const hn::Vec<D> input_vec = Set(d, input);

    HWY_ALIGN constexpr T gte_keys[] = { 0x2E3A, 0x3400, 0x4E00, 0xF900, /* ... */ };
    HWY_ALIGN constexpr T lte_keys[] = { 0x2E3A, 0x4DBF, 0x9FFF, 0xFAFF, /* ... */ };

    size_t i = 0;
    for (; i + N <= array_size(lte_keys) && lte_keys[i] != 0; i += N) {
        const hn::Vec<D> lte_vec = hn::Load(d, lte_keys + i);
        const hn::Vec<D> gte_vec = hn::Load(d, gte_keys + i);
        const intptr_t idx = hn::FindFirstTrue(
            d, hn::And(hn::Le(input_vec, lte_vec), hn::Ge(input_vec, gte_vec)));

        if (idx >= 5) return 0;       // zero-width
        else if (idx >= 0) return 2;  // wide
    }

    return 1; // normal width
}Rust (highway)use highway::{dispatch, WithSimd, SimdOps};

struct WidthKernel { input: u16 }

impl WithSimd for WidthKernel {
    type Output = i8;

    fn with_simd<S: SimdOps>(self, s: S) -> i8 {
        let n = s.lanes::<u16>();
        let input_vec = unsafe { s.splat::<u16>(self.input) };

        static GTE_KEYS: &[u16] = &[0x2E3A, 0x3400, 0x4E00, 0xF900, /* ... */];
        static LTE_KEYS: &[u16] = &[0x2E3A, 0x4DBF, 0x9FFF, 0xFAFF, /* ... */];

        let mut i = 0;
        while i + n <= LTE_KEYS.len() && LTE_KEYS[i] != 0 {
            unsafe {
                let lte_vec = s.load_u(LTE_KEYS.as_ptr().add(i));
                let gte_vec = s.load_u(GTE_KEYS.as_ptr().add(i));
                let in_range = s.and_mask(s.le(input_vec, lte_vec),
                                          s.ge(input_vec, gte_vec));
                if let Some(idx) = s.find_first_true(in_range) {
                    if idx >= 5 { return 0; }      // zero-width
                    else        { return 2; }       // wide
                }
            }
            i += n;
        }

        1 // normal width
    }
}

let width = dispatch(WidthKernel { input: 0x4E00 }); // CJK Unified Ideograph
assert_eq!(width, 2); // wide
u/ILYAMALIK — 4 months ago
▲ 27 r/rust

A SwissTable hash map with direct SSE2 SIMD — works on stable Rust, support custom alloc,build_hasher and can keys can be embedded to value

PR's are welcome,current direct intrinsics  is only available for x86_64

Benchmark probemap hb+fxhash hb+foldhash vs hb+fxhash
insert (random) 6.03 µs 6.51 µs 6.89 µs -7%
insert (serial) 4.55 µs 5.90 µs 6.64 µs -23%
grow_insert 19.8 µs 21.7 µs 27.3 µs -9%
lookup (random) 2.83 µs 4.11 µs 4.47 µs -31%
lookup (serial) 2.73 µs 4.11 µs 4.58 µs -34%
lookup_fail 2.71 µs 3.17 µs 3.54 µs -15%
insert_erase 10.0 µs 15.4 µs 16.0 µs -35%
iter 1.21 µs 1.25 µs 1.25 µs -3%
clone 1.19 µs 1.25 µs 1.29 µs -5%

https://github.com/NikoMalik/probemap

reddit.com
u/ILYAMALIK — 5 months ago