<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amy on Medium]]></title>
        <description><![CDATA[Stories by Amy on Medium]]></description>
        <link>https://medium.com/@andy_5304?source=rss-94234ea92964------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WQD6FZLfV6UQJZtU</url>
            <title>Stories by Amy on Medium</title>
            <link>https://medium.com/@andy_5304?source=rss-94234ea92964------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 02:04:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andy_5304/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Ethereum is slow — and how we can fix it]]></title>
            <link>https://medium.com/@andy_5304/why-ethereum-is-slow-and-how-we-can-fix-it-d54bb69a9ab1?source=rss-94234ea92964------2</link>
            <guid isPermaLink="false">https://medium.com/p/d54bb69a9ab1</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[ecdsa]]></category>
            <category><![CDATA[simd]]></category>
            <category><![CDATA[keccak256]]></category>
            <dc:creator><![CDATA[Amy]]></dc:creator>
            <pubDate>Mon, 30 Mar 2026 10:27:37 GMT</pubDate>
            <atom:updated>2026-03-30T10:27:37.119Z</atom:updated>
            <content:encoded><![CDATA[<h4>By re-writing ECDSA and KECCAK with SIMD arithmetic, asmcrypto makes Ethereum run faster.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*IonsDIHt8KrEa1C8iTal-A.png" /></figure><p>Ethereum Mainnet has a theoretical maximum Transactions per second (TPS) of 238 — assuming the simplest transactions, Externally Owned Accounts (EOA) where we can only transfer the ETH gas coin from one account to another. For more complex transactions, we must execute code on the Ethereum Virtual Machine (EVM) which is compute intensive. What is it that make Ethereum so slow and how can we fix it?</p><p>We’ll show that by thinking orthogonally about algorithms used in blockchains, we can make almost any blockchain run a lot faster with tens of thousands of complex transactions per second possible on modest hardware.</p><h4>Part 1 — Networking</h4><p>The Ethereum Mainnet is composed of many nodes which are mostly instances running on cloud servers. A subset of these nodes, those hosting validators, must exchange messages to reach consensus with one node proposing a block and at least 128 of these must take part in a “committee” to vote on the validity of the block. This involves exchanging many messages over poor internet connections with high latency and then broadcasting the result to all the other nodes on the network. This is a limiting factor.</p><p>Mainnet does not attempt to be fast, instead it prefers to be reliable. It has a slow block time of 12s to allow time for nodes to send their messages and has mechanisms to deal with unresponsive nodes through economic incentives. With a large number of nodes — over 10k according to Etherscan’s node tracker — getting agreement takes time.</p><h4>Part 2 — ECDSA and KECCAK</h4><p>On faster networks, we are still limited by network latency but another problem becomes apparent. Every transaction is signed using the Elliptic Curve Digital Signature Algorithm (ECDSA) and the public key (your Ethereum address) must be recovered from the signature of the KECCAK hash of the transaction bytes.</p><p>This ECDSA recovery takes around 30μs per thread on a modern desktop machine and probably a lot more on cloud hardware which is highly virtualised.</p><p>The state root of the block is calculated using many thousands of KECCAK hashes. Existing implementations of KECCAK are suboptimal, resulting in the state root taking quite a long time to execute.</p><p>We can use more threads to compute ECDSA recovery, but threads cost money.</p><p>The “gold standard” of ECDSA is the <strong>secp256k1</strong> library which has many “tricks” for computing the modulo arithmetic and equation solutions of ECDSA and contains collective years of work to improve its performance, but as we will show, <strong>this can be beaten</strong>.</p><p>Likewise, <strong>tinykeccak</strong> is the most commonly used keccak library in the Rust space We will show that we can beat this too.</p><h4>Part 3 — The EVM</h4><p>Even if we fix the problem with the ECDSA recovery and state root calculation, we then need to look at the EVM. The EVM is a 256 bit stack-based interpreter that executes code in contracts. Existing implementations such as Revm, the Rust EVM, are interpreters. They typically take hundreds of machine instructions to execute every virtual instruction.</p><p>But interpreters are not the only way to execute code. We’ll show that we can get two to three orders of magnitude improvement in execution performance.</p><h4>Fixing RPC and networking</h4><p>The fastest standards-compliant Ethereum engine is currently Reth.</p><p><a href="https://github.com/paradigmxyz/reth/issues">https://github.com/paradigmxyz/reth</a></p><p>Ethereum uses JSON RPC to interact with the chain. <strong>asmjson</strong> is a library intended to fix performance issues of existing JSON parsers such as serde_json.</p><p><a href="https://github.com/atomicincrement/asmjson">GitHub - atomicincrement/asmjson</a></p><p>This library uses SIMD instructions to classify 64 bytes of JSON text at a time, skipping characters without needing to check them. This gains an order of magnitude over more pedestrian JSON libraries.</p><p>The <strong>rbft</strong> Ethereum network is a fast qbft-style Ethereum implementation using Reth which achieves 14k+ TPS on a single node.</p><p><a href="https://github.com/raylsnetwork/rbft/">GitHub - raylsnetwork/rbft: Rayls Byzantine Fault Tolerant consensus built on Reth</a></p><h4>Fixing KECCAK and ECDSA</h4><p><strong>asmcrypto</strong> is a library for improving KECCAK and ECDSA performance without using large numbers of threads. Like <strong>asmjson</strong> it uses AVX512BW SIMD instructions. This library provides two functions, one that computes eight register-parallel KECCAK hashes and the other the computes eight register-parallel ECDSA key recoveries.</p><p><a href="https://github.com/atomicincrement/asmcrypto">GitHub - atomicincrement/asmcrypto</a></p><p>These functions are still at an early stage but are faster than <strong>libsecp256k1</strong> recovery by about 40% and <strong>tinykeccak</strong> by six times.</p><p>These functions need further work with the functions re-worked in assembly like <strong>asmjson</strong> which is 40% assembly code.</p><h4>Fixing the EVM</h4><p>There must be more “fast” EVMs out there than stars in the night sky. I have a nascent project to JIT compile Ethereum contracts. This is showing good promise at present, but needs some work to cover 100% of EVM test vectors. tests show about 250x performance improvement so far over interpreted EVM bytecode. Challenges include optimising out MSTORE/MLOAD pairs, computing dominance of the control flow graph and reducing most 256 bit operations to 64 bits.<br>There are plans afoot to use RiscV as the EVM bytecode and this technique could be extended to this, although our work with EVM brings new life to the old bytecode.</p><p>I’ll release this project when it can execute the whole of Mainnet — perhaps in a few minutes if the database support is also fast.</p><h4>Conclusions</h4><p>It is possible to boost the performance of Ethereum by several orders of magnitude without changing the design. The JSON RPC, ECDSA recovery, execution and state root calculation all can be improved.</p><p>Reth is currently the winner in the Ethereum node stakes but once our current suite of libraries is considered stable, we can show considerable performance improvement by combining Reth with high performance algorithms.</p><p>If you want to contribute to the development of these libraries with time or money, get in touch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d54bb69a9ab1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing the ultimate SIMD JSON parser with Claude]]></title>
            <link>https://medium.com/@andy_5304/writing-the-ultimate-simd-json-parser-with-claude-2bd33a6eda05?source=rss-94234ea92964------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bd33a6eda05</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[simd]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[assembly-language]]></category>
            <dc:creator><![CDATA[Amy]]></dc:creator>
            <pubDate>Wed, 25 Mar 2026 11:42:21 GMT</pubDate>
            <atom:updated>2026-03-25T11:42:21.595Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will talk about writing parsers with SIMD CPU architectures and how we used Claude to implement the architecture.</p><p>Using ASM and SIMD we are able to nearly double the performance of the incumbent champion, <strong>sonic-rs,</strong> and gain an order of magnitude over <strong>serde_json</strong>’s DOM.</p><p>The success of this project points the way to a new generation of agentic compilers which can generate better code than exisiting technology.</p><h4>Understanding JSON</h4><p>Writing JSON parsers is a bit of a competitive sport in the coding world. JSON is everywhere and by far the most popular data interchange format for its sins. There are many more efficient structured data exchange formats, but JSON is human readable and remarkably simple.</p><p>In blockchains, JSON is used for the RPC interface that talks to web apps, indexers and MEV bots. Internally, Ethereum uses the RLP binary format which is much more compact.</p><p>Writing a basic JSON parser is simple, a JSON value has.</p><ul><li>Strings — “hello”</li><li>Objects — {“age”: 100}</li><li>Arrays — [1, 2, 3]</li><li>Atoms — 1.4, true, false, null</li></ul><p>To parse a JSON value, we just check the first character and then scan the remaining characters until we find a terminator. For output, we either build a DOM model in binary which we can then random access or use a SAX interface which the parser calls with each kind of value. DOM works best when there is a small amount of data, SAX works best when the source string is potentially infinite, as in the case of a memory mapped file.</p><h4>Thread parallelism</h4><p>For large amounts of data, we often see “JSON lines” files or streams where each line of the file is a JSON object:</p><pre>{&quot;name&quot;:&quot;fred&quot;,&quot;age&quot;:33}<br>{&quot;name&quot;:&quot;jim&quot;,&quot;age&quot;:22}</pre><p>Here we can accelerate parsing by breaking the file or stream into large chunks at newline boundaries and using thread parallelism to parse the individual lines in the chunks.</p><p>But there is a much more subtle and less costly way to do this and that is <em>register parallelism</em>.</p><h4>Register parallelism</h4><p>On the current (2026) x86 architectures we have very wide word registers. The AVX512BW architecture is ideal for fast parsing as it has the ability to:</p><ul><li>Read up to 64 bytes with a single masked load.</li><li>Compare all 64 bytes with a single instruction.</li><li>Convert that compare to a 64 bit integer bit pattern.</li></ul><p>As a result, we end up with a bit pattern that represents.</p><ul><li>Whitespace</li><li>Quotes</li><li>Backslashes — for escaped strings</li><li>Delimiters — , : } ]</li></ul><p>We can build a Deterministic Finite Automaton from the JSON grammar which represents the various points in the parsing where we can be. For example at the start of a string, at the start of an array etc.</p><p>At each of the states of the DFA we usually want to skip a class of characters to determine where the next token is</p><ul><li>Find the next non-whitespace character</li><li>Find a closing quote or backslash</li><li>Find a delimiter character.</li></ul><p>With the bitmasks generated by the classification process, all these skips become easy — just use the TZCNT instruction (trailing zero count). As a result we visit each state much less frequently and that gives us our edge.</p><h4>Implementation using Claude Sonnet 4.6</h4><p>To teach Claude how to do this, I started with a simple DFA parser for JSON in Rust. I implemented a swap-able classifier function which was chosen using the CPUID runtime cpu architecture.<br>For older CPUs Claude knew how to implement a SWAR (SIMD within a register) classifier using the tricks from Hacker’s Delight and other masterworks of coding. For newer CPUs we had either AVX2 (256 bit) or AVX512BW (512 bit registers).</p><p>With this Rust implementation working as a reference, I then asked Claude to translate the code into x86_64 ASM. The translation was surprisingly good, at least as good as LLVM, <strong>which spawns the idea of writing a LLM based compiler</strong>! With agents writing such good ASM it begs the question of whether we actually need high level languages at all, especially if the puny humans don’t every check their generated code :)</p><p>But that was only the start as I have considerable experience improving ASM code to get high performance, low latency code in ASM.</p><h4>Register allocation, Scheduling and memory bandwidth.</h4><p>I was able to have a good conversation about the register allocation with the agent. Getting as much into registers as possible is the key to high performance ASM. Clause was also able to discuss the scheduling of instructions. We ran llvm-mca to check the register pressures although scoreboarding (instruction reordering in the CPU) often makes this a work of fiction. I also tried a few memory tricks including using non-temporal stores for the DOM version of the ASM.</p><p>Clause was able to maintain several parallel versions of the ASM code, something that would have been tedious in the past. I could have used macros to make common code, but why bother when it is easy to keep several versions in sync “manually”.</p><p>Generating code for ARM SVE platforms would be just as easy if I only had some hardware. ARM has 32 integer registers which makes tracking a large state very easy.</p><h4>Calling conventions</h4><p>To call my code from Rust, Claude had correctly generated the system V calling convention. The callbacks for the SAX version saved registers and restored them — there was one error which Claude spotted by way of testing.</p><p>Internally, it is possible to call functions with no stack frame — reducing critical iCache footprint.</p><h4>Correctness</h4><p>I allowed a little “permissive” behaviour in the parser which would be easy to correct with additional code. For example, the whitespace characters in the JSON spec are limited and I allowed all control characters and space. I also didn’t check the strings for control characters. It would be easy to add this if such pedantry was required. I would suggest both permissive and formal parser variants and maybe support for comments, too.</p><p>I would need to do a lot more testing to convince myself that the implementation is correct. The current version is not ready for production and would need many pairs of eyes on it to increase the probability of correctness (those who claim 100% correctness in their projects are usually lying).</p><h4>Performance</h4><p>On my 9955HX AMD MiniPC the benchmark results were pretty good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*RZD1h-j6RwE0X1VH1xFPEw.png" /></figure><p>I discovered <strong>sonic-rs</strong>, a parser from Bytedance, late into the project and I had to make extra effort to beat it. It was by far the best of the crop although I don’t write off the chance of having to make extra effort if a faster parser is found. <strong>sonic-rs</strong> does do “deferred parsing” which means that a correct benchmark must “do something” with the data to be fair — in this case just count string lengths.<br>Against the regular Rust <strong>serde</strong> interface we are quite a bit faster even when using procedural macro code. <strong>serde_json</strong>’s DOM model is highly inefficient but this is a known fact.</p><p>Against <strong>simd-json</strong> we did fairly well as well. This looked quite promising at first.</p><p>All these benchmarks are single-threaded.</p><h4>The code</h4><p>The code is on github:</p><p><a href="https://github.com/atomicincrement/asmjson">GitHub - atomicincrement/asmjson</a></p><p>It also has docs.rs and crates.io publication.</p><h4>Reception</h4><p>r/rust blocked the publication of this crate describing it as “AI slop”. I’m guessing they used AI tools to reach this conclusion as they gave no explanation. I wear this as a badge of pride.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bd33a6eda05" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>