Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

ada

> 数据库
Open source

WHATWG-compliant and fast URL parser written in modern C++, part of Internet Archive, Node.js, Clickhouse, Redpanda, Kong, Telegram, Adguard, Datadog and Cloudf

1.8K stars0 likes1 views
WebsiteGitHub

About

WHATWG-compliant and fast URL parser written in modern C++, part of Internet Archive, Node.js, Clickhouse, Redpanda, Kong, Telegram, Adguard, Datadog and Cloudf

Ada

Ada is a fast and spec-compliant URL parser written in C++. Specification for URL parser can be found from the WHATWG website.

Ada library also includes a URLPattern implementation that is compatible with the web-platform tests.

The Ada library passes the full range of tests from the specification, across a wide range of platforms (e.g., Windows, Linux, macOS). It fully supports the relevant Unicode Technical Standard.

A common use of a URL parser is to take a URL string and normalize it. The WHATWG URL specification has been adopted by most browsers. Other tools, such as curl and many standard libraries, follow the RFC 3986. The following table illustrates possible differences in practice (encoding of the host, encoding of the path):

string source string value
input string https://www.7‑Eleven.com/Home/Privacy/Montréal
ada's normalized string https://www.xn--7eleven-506c.com/Home/Privacy/Montr%C3%A9al
curl 7.87 (returns the original unchanged)

Ada is fast.

On a benchmark where we need to validate and normalize thousands URLs found on popular websites, we find that ada can be several times faster than popular competitors (system: Apple MacBook 2022 with LLVM 14).

      ada ▏  188 ns/URL ███▏
servo url ▏  664 ns/URL ███████████▎
     CURL ▏ 1471 ns/URL █████████████████████████

Ada has improved the performance of the popular JavaScript environment Node.js:

Since Node.js 18, a new URL parser dependency was added to Node.js — Ada. This addition bumped the Node.js performance when parsing URLs to a new level. Some results could reach up to an improvement of 400%. (State of Node.js Performance 2023)

The Ada library is used by important systems besides Node.js such as Redpanda, Kong, Telegram, DataDog, and Cloudflare Workers.

Requirements

The project is otherwise self-contained and it has no dependency. A recent C++ compiler supporting C++20. We test GCC 12 or better, LLVM 14 or better and Microsoft Visual Studio 2022.

Installation

Binary packages for the following systems are currently available:

Quick Start

Linux or macOS users might follow the following instructions if they have a recent C++ compiler installed and a standard utility (wget)

  1. Pull the library in a directory

    bash
    wget https://github.com/ada-url/ada/releases/download/v3.0.0/ada.cpp
    wget https://github.com/ada-url/ada/releases/download/v3.0.0/ada.h
  2. Create a new file named demo.cpp with this content:

    cpp
     #include "ada.cpp"
     #include "ada.h"
     #include <iostream>
    
     int main(int, char *[]) {
       auto url = ada::parse("https://www.google.com");
       if (!url) {
         std::cout << "failure" << std::endl;
         return EXIT_FAILURE;
       }
       url->set_protocol("http");
       std::cout << url->get_protocol() << std::endl;
       std::cout << url->get_host() << std::endl;
       return EXIT_SUCCESS;
     }
  3. Compile

    c++ -std=c++20 -o demo demo.cpp
  4. ./demo

    http:
    www.google.com

Bindings of Ada

The following libraries are maintained by the Ada team and available under Ada GitHub organization.

  • Rust: Rust bindings for Ada
  • Go: Go bindings for Ada
  • Python: Python bindings for Ada
  • Kotlin: Kotlin bindings for Ada

Community maintained

  • R: R wrapper for Ada
  • PHP: PHP Wrapper for Ada URL
  • LuaJIT: LuaJIT FFI bindings for Ada
  • Zig: Unofficial Zig bindings for Ada
  • Python: Python bindings for Ada
  • React Native: A Fast URL and URLSearchParams polyfill for React Native.
  • D: D bindings for Ada, @nogc, nothrow and @safe compat.

Usage

Ada supports two types of URL instances, ada::url and ada::url_aggregator. The usage is the same in either case: we have an parsing function template ada::parse which can return either a result of type ada::result<ada::url> or of type ada::result<ada::url_aggregator> depending on your needs. The ada::url_aggregator class is smaller and it is backed by a precomputed serialized URL string. The ada::url class is made of several separate strings for the various components (path, host, and so forth).

Parsing & Validation

  • Parse and validate a URL from an ASCII or a valid UTF-8 string.
cpp
auto url = ada::parse<ada::url_aggregator>("https://www.google.com");
if (url) { /* URL is valid */ }

After calling 'parse', you must check that the result is valid before accessing it when you are not sure that it will succeed. The following code is unsafe:

cpp
auto> url = ada::parse<ada::url_aggregator>("some bad url");
url->get_href();

For simplicity, in the examples below, we skip the check because we know that parsing succeeds. All strings are assumed to be valid UTF-8 strings.

Examples

URL Parser

…

URL Size Limit

By default, ada allows URLs up to about 4 GB. You can set a lower limit to reject any URL whose serialized form (the href) would exceed a given number of bytes. The limit is enforced during parsing and across all setters. Setters that return bool return false when the limit would be exceeded; void setters (set_search, set_hash) silently leave the URL unchanged. In all cases the URL is never modified when a limit violation is detected. Percent-encoding expansion is accounted for: a short input that encodes into a long result is still rejected.

…

You can query the byte length of a URL without allocating a string via get_href_size():

cpp
auto url = ada::parse<ada::url_aggregator>("https://example.com/path");
assert(url);
size_t len = url->get_href_size();  // no allocation
assert(len == url->get_href().size());

URL Search Params

cpp
ada::url_search_params search_params("a=b&c=d&e=f");
search_params.append("g=h");

search_params.get("g");  // will return "h"

auto keys = search_params.get_keys();
while (keys.has_next()) {
  auto key = keys.next();  // "a", "c", "e", "g"
}

URLPattern

Our implementation doesn't provide a regex engine and leaves the decision of choosing the right engine to the user. This is done as a security measure since the default std::regex engine is not safe and open to DDOS attacks. Runtimes like Node.js and Cloudflare Workers use the V8 regex engine, which is safe and performant.

…

URLPattern List (experimental)

A URLPattern list is a set of pathname patterns compiled together, so that finding the matching route is one lookup instead of a loop over url_pattern::exec. It takes the same regex provider as parse_url_pattern, and only routes that need regexp semantics (custom (...) groups, ?, + or * modifiers) ever reach it. Static, :param and * routes are matched without a regex engine.

…

Things to know:

  • match takes a pathname, not a full URL. Only the pathname is matched; the other components are treated as wildcards.
  • The most specific route wins: a literal segment beats :param, which beats *, compared segment by segment from the left. Between equally specific routes, the one added first wins. /users/me wins over /users/:id for /users/me whatever the insertion order. This is the order used by routers such as find-my-way and Express.
  • Regexp routes take part in the same order. A regexp route that cannot beat the compiled winner is not executed at all.
  • parse_url_pattern_list also takes a base URL and url_pattern_options (ignore_case), and an overload takes existing ada::url_pattern objects and reuses their compiled pathname components.
  • Inputs over 4096 bytes or 24 segments, and routes with more than 16 segments, are handled by a slower path with the same result. A route may declare up to 8 captures; beyond that only the first 8 are reported and captures_truncated is set.

The API is experimental. Whether a standard URLPatternList should use this order or plain insertion order is still being discussed in the WHATWG urlpattern repository.

C wrapper

See the file include/ada_c.h for our C interface. We expect ASCII or UTF-8 strings.

…

When linking against the ada library from C++, be minding that ada requires access to the standard C++ library. E.g., you may link with the C++ compiler.

E.g., if you grab our single-header C++ files (ada.cpp and ada.h), as well as the C header (ada_c.h), you can often compile a C program (demo.c) as follows under Linux/macOS systems:

c++ -c ada.cpp -std=c++20
cc -c demo.c
c++ demo.o ada.o -o cdemo
./cdemo

Command-line interface

For more information about command-line options, please refer to the CLI documentation.

CMake dependency

See the file tests/installation/CMakeLists.txt for an example of how you might use ada from your own CMake project, after having installed ada on your system.

Contributing

Contributors are encouraged to read our AI Tool Policy.

Building

Ada uses cmake as a build system. It's recommended you to run the following commands to build it locally.

Without tests:

  • Build: cmake -B build && cmake --build build

With tests (requires git):

  • Build: cmake -B build -DADA_TESTING=ON && cmake --build build
  • Test: ctest --output-on-failure --test-dir build

With tests (requires available local packages):

  • Build: cmake -B build -DADA_TESTING=ON -D CPM_USE_LOCAL_PACKAGES=ON && cmake --build build
  • Test: ctest --output-on-failure --test-dir build

Build options

Ada provides several CMake options to customize the build:

  • ADA_USE_SIMDUTF: Enables SIMD-accelerated Unicode processing via simdutf (default: OFF)

Windows users need additional flags to specify the build configuration, e.g. --config Release.

Amalgamation

You may amalgamate all source files into only two files (ada.h and ada.cpp) by typing executing the Python 3 script singleheader/amalgamate.py. By default, the files are created in the singleheader directory.

License

This code is made available under the Apache License 2.0 as well as the MIT license.

Our tests include third-party code and data. The benchmarking code includes third-party code: it is provided for research purposes only and not part of the library.

Further reading

  • Yagiz Nizipli, Daniel Lemire, Parsing Millions of URLs per Second, Software: Practice and Experience 54(5) May 2024.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++cppneonparserperformance

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库