# Optimization techniques for EVM implementations by Paweł Bylica (Devcon5)

- Speakers: [Paweł Bylica](https://streameth.org/speakers/pawe-bylica)
- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2020-10-09
- Duration: 22:58
- Topics: blockchain, smart contracts, distributed ledger, ethereum
- Watch: https://streameth.org/watch/yt-2ZAh7NmjOXM
- YouTube: https://www.youtube.com/watch?v=2ZAh7NmjOXM

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more.
https://archive.devcon.org/archive/watch/5/optimization-techniques-for-evm-implementations

A number of optimization techniques for Ethereum Virtual Machine implementations are going to be presented along with examples and benchmarks based on evmone and EVMJIT projects.
Based on performed benchmarks, the presentation will show ~10x speed improvements in evmone comparing to other EVM implementations.
 While evmone is build in C++, the optimizations are not limited to C++. All of the optimizations are applicable to any compiled language, some of them even to interpreted languages.

Speaker(s): Paweł Bylica
Skill level: Advanced
Track: Execution Layer
Keywords: technical

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 5 was held in Osaka, Japan on Oct 8 - 11, 2019.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

[Applause] has to skilful place to have some of these five so the official title techniques this is the better one will be how to be able to fight again yeah okay but thirty two sides say this is not talk about all thing I am going to [Music] for nothing because of that produces advanced degrees in the generic interpersonal simulation space my name is Paulo good job and I was for many years I do enhance so let me go through like my history of working with EPM I started quite an elite even before the team has life and the first project I was working for with my colleague was EDM jet so it was it was a product that was supposed to prove that in the end it was working by was translating he my coach to be my heart and their music LLVM doing it was it was compiling that to machine code loaded loaded to memory and then it was executed as a native code so the product died around 2017 signals mostly not interested like using it Fedora to prove it long time ago it's absolute ago but I think the big controversy about collages compilation part line like consensus critical critical but what actually come out out of the end of the product was a DMZ which was attempt to and still is attempt to define the low-level API for a VM and actually for both sides or ETS and acquire those days and is one of the site implemented it can use like different implementations of EBS more more like a way of as a supply base work and the first point here is a project which originally was the CPP is helium and it has my big C++ code base it was one of the free implementation was started before as was the original two implementations but there actually we also use the e BMC API in fact the EVF implementations from the window into this API so it's it's available as and the last product is he in wattage I started last year and many of the things most of the things I am I going to prevention are coming from from discoveries to this product CPM one is this is interpreter implementing EVM and the key differences it has pretty pretty good 256 bit integer implementation and it has also experimental efficient different way of counting castings and constraints and firstly my other optimizations kind of like micro micro optimizations which are related either to C++ or maybe not but I'm going to talk about the first 2.0 and these both of these were actually least in version 0.1 sometime ago so they were down at the same time so when we started there when we want to start with the two 5/16 eater implementation so we can say it's critical from the end point of view this but this is the arc Maddox ATM uses so I chose the kind of like most realistic is like if it's maybe it's important what might be so much but was my expectation is about a pound when consumers actually recently had option to actually place the general implementation of affinity group in a live interpreter which previously was using boost multi-position so what is commonly known as Sigma's glass library some kind of standard library extension commonly using too many C++ products so I think it's nothing to be to be worried about it there's it's quite year better performance but with an option to replace that implementation with index implementation which is which is the implementation actually this 440 bm1 at this point big thanks to some internet guy called Dastak who actually contributed for this changes and use also smaller more modest like that so this is like zoom of of the benchmark small set of benchmarks I did and we will going back to that again but simply by replacing the teacher implementation we can get around three times speed improvement this is summary of evolution later so it's like a commercial end of days the average usage of the phones here but if we go back to talking about this to fight experimentation and if you can refer probably very overused at2020 room so for if you want to implement into drew it's actually what's most mostly like that so so 80% of your struggles around division which is pretty magical place to do anything else you want to implement it's pretty much straightforward so by diffusion here I was so mean reminded of the division of my module operations and so on because like there's lots of these actually coming from from the same algorithm but like if we like consuming like a short short time five year if I can leave quick its how how like how to I think the performing two five six the implementation should look like so these are some guidelines I have so first of all you can forget about any any kind of fancy algorithm that show up somewhere in the space and one most like multiplication algorithm like stage to some multiplications of the words so I mean they work as export where they actually beat big big numbers to do multiplier and so on for the the procedure is actually quite quite small precision actually comparing two numbers internal so none of them are needed and I am pretty sure that's that's correct statement but what I've also living in Texas I actually not always liked easy cases to handle so even if you have option to figure out that the numbers you have multiplied small like they would be 64 bits I think it's not worth to actually handle this case separately because like this top sort of algorithm and like you have additional conditions and conscious subtract and pretty well pretty much it works great if you if you just only focus on two five six bits and the first thing I want to mention here is like try first first optimizations you can do is try to avoid dynamic memory location so if you use any kind of generic multi number library that actually can have an arbitrary precision which are not fixed on this compile time because the size will be so if this option to use fixed like fixed position but this part of it is perfect because that's this is the memorial patient some someone is not for that but I think it's it's I think we should go further here and also like I am sure I can explain that with validation but money of the actually has keep the number of words they were later translated the number of presentation was a kind of additional information stored in the time which makes that the type bigger by this additional item and actually this so it makes it more isotonic it's out in our case methods known as 25% bigger and I think from like even the memory access patterns it's kind of important to not have it because if you have the minimum possible size which is 32 bytes it nicely fits into cash buyers and so on and when you axis start items of this size it's it's performs much faster the fifth suggestion is try to understand CPU has some kind of special instructions like other operations and high precision education and think this should be aware that when you when you get the counting and high-level language is good to know if I do compiler cookies studies by using one of artists how Drax's them or you might need to do some intrinsic stew for example access to identification and lost being in terms of division I mean I was actually starting a business because I also have to learn most of these and what this paper really taught me here so this is a paper coming from GMP library which is regulation it actually gives you like straight away maybe it's not straight away because the form is it's described in just like mathematical form so that you still have to translate it a little code but I think it goes it gives you almost Felicity how to actually provide and I didn't still JT is faster here but like knots but by some margin because maybe this they definitely use assembly direct another oil speed-up so maybe this is like somehow compiler for that is chaotic optimize the same way like something you did some time ago but if you like still lost so my suggestion is that you because the compiler options try to support de my device called Holocaust week it will ya sports the license on it it's apache2 so I mean by talking I don't mean use it in the basic in this case is on this accessing see called public enjoy that by holding I mean you can try to see ya [Music] so at IBM we actually put a bit more work in presenting price before the institution spots so I would try to explain that by example so we have a called TV and byte code us a video but you don't actually need to understand what it does actually I'd like do something in the end this one is thank you so it's actually pretty stupid now anyway what we want to do and we will try to do it what's step is doing in one so we want to identify a jukebox baby blocks are the sequence of code kind of and this coming from the compiler construction and basic doors are there the sequence of vegetation that for sure executed in the order and [Music] so what we do here we actually have a 20-block we can pick up the bass customer satisfactions but you can also pre-computer some heavy drinking execution we can check this conditions on in pervasive blog and any more information because we give information and we don't have to check it for ratings [Music] between the [Applause] you
