SEPTEMBER 30, 2025

6 MIN READ

SYLVAIN UTARD

NetQuack 4000x Faster

NetQuack 4000x Faster

We rewrote NetQuack DuckDB extension, replacing regex with character parsing. Result: 4000x faster—37 seconds down to 0.012 seconds.

Listen to this article (Gen-AI)

0:00
0:00
Blog

When we started using DuckDB more heavily at Altertable, we quickly discovered the NetQuack (community-maintained) extension for URL parsing. While functional, its performance was... disappointing. Extracting domains from URLs was taking 37 seconds for 30,000 URLs. For a database that prides itself on analytical performance, this felt wrong.

After digging into the code, the culprits were obvious: heavy reliance on std::regex for parsing and database queries to validate TLDs against the Public Suffix List. Inspired by how ClickHouse handles URL parsing, we rewrote the entire extension. This was one of 17 upstream contributions we made in 90 days. The results? Up to 4000x performance improvements across all functions.

What Was Wrong

The original NetQuack implementation had two major performance killers. First, every URL component extraction used std::regex:


Second, TLD extraction required querying a database table populated from the Mozilla Public Suffix List:


This meant every domain extraction triggered multiple database queries. For analytical workloads processing thousands of URLs, this was a disaster.

The ClickHouse-Inspired Solution

We completely rewrote the extension using character-by-character parsing instead of regex:


This approach uses std::string_view for zero-copy operations, processes one character at a time with simple switch statements, and avoids regex compilation overhead entirely.

Then, the bigger win was eliminating database dependencies. We use gperf to generate a perfect hash function from Mozilla's Public Suffix List:


This creates a collision-free hash function compiled directly into the extension binary. Now TLD lookups are O(1) memory operations instead of database queries:

The perfect hash table adds only ~500KB to the binary size but eliminates runtime PSL downloads, database table storage, query execution overhead, and memory allocations for temporary strings.


The Results

We benchmarked both versions against 30,000 URLs. The improvements were staggering:

FunctionBeforeAfterImprovement
extract_schema0.069s0.010s6.9x faster
extract_host0.086s0.008s10.7x faster
extract_port0.533s0.009s59.2x faster
extract_path0.127s0.008s15.8x faster
extract_query_string0.202s0.004s50.5x faster
extract_domain37.503s0.012s3125.2x faster
extract_subdomain35.831s0.010s3583.1x faster
extract_tld36.003s0.009s4000.3x faster
extract_extension0.329s0.007s47.0x faster

The TLD-dependent functions saw the most dramatic improvements because they eliminated both regex parsing AND database queries. The architecture change was fundamental:

  • Before: URL Input → Regex Parsing → Database Query → Result
  • After: URL Input → Character Parsing → Perfect Hash Lookup → Result

The old implementation had O(n) regex compilation per URL plus O(log n) database queries with disk I/O. The new implementation has O(n) single-pass character scanning with O(1) perfect hash lookups in memory.

And despite the complete rewrite, all existing tests pass and edge cases are handled correctly.

Key Takeaways

Profile before optimizing. The 37-second domain extraction time immediately pointed to the real bottlenecks. Always measure first.

Eliminate I/O in hot paths. Database queries in URL parsing functions were the primary performance killer. Moving to compile-time data structures eliminated this entirely.

Character parsing beats regex for simple patterns. For structured data like URLs, character-by-character parsing is often faster and more predictable than regex.

Perfect hashing works great for static data. When you have a known, static dataset (like TLDs), perfect hash functions provide optimal lookup performance.

Zero-copy string operations matter. Using std::string_view eliminated unnecessary string copying, especially important for analytical workloads.

Try It Yourself

The optimized NetQuack extension is currently under review in Pull Request #13. While we wait for the maintainer to review and hopefully merge these changes, you can:

  1. Test the optimized version by building from our branch:

    
    
  2. Run the benchmarks yourself to see the performance improvements:

    
    
  3. Check out the source code on GitHub to see the detailed implementation.


This optimization journey reminded us why performance matters in analytical databases. When you're processing millions of URLs, the difference between 37 seconds and 0.012 seconds isn't just a nice-to-have—it's the difference between interactive analysis and waiting for coffee to brew.

Sometimes the best optimization is throwing out the old approach entirely and starting fresh with the right architectural principles. In this case, ClickHouse showed us the way.

Share

Sylvain Utard, Co-Founder & CEO at Altertable

Sylvain Utard

Co-Founder & CEO

Seasoned leader in B2B SaaS and B2C. Scaled 100+ teams at Algolia (1st hire) & Sorare. Passionate about data, performance and productivity.

Stay Updated

Get the latest insights on data, AI, and modern infrastructure delivered to your inbox

Related Articles

Continue exploring topics related to this article

AI's Event Backbone
MARCH 10TH, 2026
Sylvain Utard

AI's Event Backbone

Product, Performance, Engineering

AI-native products generate a new kind of infrastructure problem. Here's how to build the event backbone for your AI system.

READ ARTICLE
One Billion Rows
FEBRUARY 17TH, 2026
Sylvain Utard

One Billion Rows

Product, Performance, Engineering

At 1 billion rows, every shortcut comes back to collect interest. Here's how we achieved sub-second queries with near-realtime ingestion.

READ ARTICLE
Lessons from Search
JANUARY 13TH, 2026
Sylvain Utard

Lessons from Search

Performance, Architecture, Engineering

Real-time analytics faces the small-file problem search engines solved. DuckLake's tiered compaction brings those merge strategies to streaming analytics.

READ ARTICLE
Pruning Top-N Queries
FEBRUARY 3RD, 2026
Sylvain Utard

Pruning Top-N Queries

Open Source, Performance, Architecture

A deep dive into DuckLake PR #668 and how Top-N dynamic filter pruning turns ORDER BY + LIMIT from full scans into metadata-driven execution.

READ ARTICLE
Stop Batching Analytics
DECEMBER 30TH, 2025
Sylvain Utard

Stop Batching Analytics

Analytics, Architecture, Performance

Why we're forcing analytics through complex batch pipelines when append-only data should work like logs. The warehouse constraint that stopped making sense.

READ ARTICLE
Altertable Logo

Stop paying for idle warehouses

Join engineering, product, and data teams switching to the operational lakehouse