All Projects → nodejs → Llhttp

nodejs / Llhttp

Licence: other
Port of http_parser to llparse

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Llhttp

Coriander
Build NVIDIA® CUDA™ code for OpenCL™ 1.2 devices
Stars: ✭ 665 (-20.93%)
Mutual labels:  llvm
Mbx
Supplementary material for my talk
Stars: ✭ 6 (-99.29%)
Mutual labels:  llvm
Llvm Tutor
A collection of out-of-tree LLVM passes for teaching and learning
Stars: ✭ 941 (+11.89%)
Mutual labels:  llvm
Rust Python Example
Example of using Rust to Extend Python
Stars: ✭ 699 (-16.88%)
Mutual labels:  llvm
Qbdi
A Dynamic Binary Instrumentation framework based on LLVM.
Stars: ✭ 801 (-4.76%)
Mutual labels:  llvm
Swift Llbuild
A low-level build system, used by Xcode and the Swift Package Manager
Stars: ✭ 836 (-0.59%)
Mutual labels:  llvm
Llvmswift
A Swift wrapper for the LLVM C API (version 9.0.1)
Stars: ✭ 641 (-23.78%)
Mutual labels:  llvm
Woboq codebrowser
Woboq CodeBrowser
Stars: ✭ 837 (-0.48%)
Mutual labels:  llvm
Swift Llvm
Stars: ✭ 802 (-4.64%)
Mutual labels:  llvm
Vivado hls tutorial
Source code of basic Xilinx Vivado HLS image processing tutorial using HLS openCV functions
Stars: ✭ 17 (-97.98%)
Mutual labels:  llvm
Inkwell
It's a New Kind of Wrapper for Exposing LLVM (Safely)
Stars: ✭ 732 (-12.96%)
Mutual labels:  llvm
Numba
NumPy aware dynamic Python compiler using LLVM
Stars: ✭ 7,090 (+743.04%)
Mutual labels:  llvm
Jucipp
A lightweight & cross-platform IDE supporting the most recent C++ standards. This project has moved to https://gitlab.com/cppit/jucipp.
Stars: ✭ 887 (+5.47%)
Mutual labels:  llvm
Llvm
Library for interacting with LLVM IR in pure Go.
Stars: ✭ 670 (-20.33%)
Mutual labels:  llvm
Ldc
The LLVM-based D Compiler.
Stars: ✭ 937 (+11.41%)
Mutual labels:  llvm
Gocaml
🐫 Practical statically typed functional programming language implementation with Go and LLVM
Stars: ✭ 653 (-22.35%)
Mutual labels:  llvm
Grin
GRIN is a compiler back-end for lazy and strict functional languages with whole program optimization support.
Stars: ✭ 834 (-0.83%)
Mutual labels:  llvm
Cfl
a Compileable statically typed Functional programming Language
Stars: ✭ 7 (-99.17%)
Mutual labels:  llvm
Pragmascript
Stars: ✭ 7 (-99.17%)
Mutual labels:  llvm
Avrd
Embedded Systems in D - Port of avr-libc headers and most avr-gcc processor defines
Stars: ✭ 17 (-97.98%)
Mutual labels:  llvm

llhttp

CI

Port of http_parser to llparse.

Why?

Let's face it, http_parser is practically unmaintainable. Even introduction of a single new method results in a significant code churn.

This project aims to:

  • Make it maintainable
  • Verifiable
  • Improving benchmarks where possible

More details in Fedor Indutny's talk at JSConf EU 2019

How?

Over time, different approaches for improving http_parser's code base were tried. However, all of them failed due to resulting significant performance degradation.

This project is a port of http_parser to TypeScript. llparse is used to generate the output C source file, which could be compiled and linked with the embedder's program (like Node.js).

Performance

So far llhttp outperforms http_parser:

input size bandwidth reqs/sec time
llhttp 8192.00 mb 1777.24 mb/s 3583799.39 req/sec 4.61 s
http_parser 8192.00 mb 694.66 mb/s 1406180.33 req/sec 11.79 s

llhttp is faster by approximately 156%.

Maintenance

llhttp project has about 1400 lines of TypeScript code describing the parser itself and around 450 lines of C code and headers providing the helper methods. The whole http_parser is implemented in approximately 2500 lines of C, and 436 lines of headers.

All optimizations and multi-character matching in llhttp are generated automatically, and thus doesn't add any extra maintenance cost. On the contrary, most of http_parser's code is hand-optimized and unrolled. Instead describing "how" it should parse the HTTP requests/responses, a maintainer should implement the new features in http_parser cautiously, considering possible performance degradation and manually optimizing the new code.

Verification

The state machine graph is encoded explicitly in llhttp. The llparse automatically checks the graph for absence of loops and correct reporting of the input ranges (spans) like header names and values. In the future, additional checks could be performed to get even stricter verification of the llhttp.

Usage

#include "llhttp.h"

llhttp_t parser;
llhttp_settings_t settings;

/* Initialize user callbacks and settings */
llhttp_settings_init(&settings);

/* Set user callback */
settings.on_message_complete = handle_on_message_complete;

/* Initialize the parser in HTTP_BOTH mode, meaning that it will select between
 * HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
 * input.
 */
llhttp_init(&parser, HTTP_BOTH, &settings);

/* Parse request! */
const char* request = "GET / HTTP/1.1\r\n\r\n";
int request_len = strlen(request);

enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
if (err == HPE_OK) {
  /* Successfully parsed! */
} else {
  fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err),
          parser.reason);
}

Bindings to other languages

LICENSE

This software is licensed under the MIT License.

Copyright Fedor Indutny, 2018.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].