Building Efficient Software
Your Host Tonight
Desarrollador senior en LogTrust
What We Will Cover
- Slow and Fast Software
- Finding Hot Spots
- Load Testing
- Micro Profiling
Slow and Fast Software
The day comes when some client tells you:
Your Software Is Slow
Well, it happens to everyone
MY SOFTWARE IS NOT SLOW, COLONEL!
But is it slow?
What is it doing?
Can it be made faster?
Can you distract the user?
Can you avoid doing some things?
What Is Your Software Doing...
...with all those CPU cycles?
Each second has ~4·109 cycles
Each toolchain has a max efficiency
Node.js: interpreter + compiler
The real problem is that programmers
have spent far too much time
worrying about efficiency
in the wrong places and at the wrong times;
premature optimization is the root of all evil
(or at least most of it) in programming.
— Donald Knuth, computer scientist
... is not written fast
Which is faster?
- 2016: Lenovo X1 Carbon 4g (Windows)
- 2016: Samsung Galaxy S7
- 2002: Apple iMac G4
- 1993: Mac Color Classic
- 2017: Apple iPhone X
- 1998: Nintendo Gameboy Color
- 2017: Lenovo ThinkPad 13 (ChromeOS)
- 2017: Apple iPad Pro 10.5"
- 1977: Commodore Pet 4016
- 2017: Apple iPad Pro 10.5" pencil
- 1983: Apple 2e
Source: Dan Luu
Finding Hot Spots
80% of the effects come
from 20% of the causes
— Vilfredo Pareto, Italian Sociologist*
*Not known for his many catchy quotes
Worry about the most relevant causes
Used in many engineering areas
Can be used recursively!
64% of the effects come
from 4% of the causes
... and the long tail
It’s this simple: if you don’t sample,
you don’t scale.
If you think this is even a controversial statement,
you have never dealt with observability at scale OR you have done it wastefully and poorly.
— Charity Majors, computer engineer
Design Load Tests
Bring the problem to the laboratory
Load Test Demo
— Grace Hopper, computer engineer
Time to measure matters
Max resolution depends on measure
Measurement noise can kill you!
Sidebar: 32-bit Multiplication
Lies, damn lies
There are three gradations of inveracity:
there are lies, there are damned lies
and there are statistics
— Arthur James Balfour, UK Prime Minister
Usually can get any precision desired
Your mileage may vary — wildly!
Handle with care
Once the hot spot is replicated you can optimize it
It is usually harder than solving a regular bug
Work through the layers: interpreter, optimizer...
Until you need to
And even then...
Don't micro-optimize blindly
Keep your target in sight
There are multiple obstacles on any path
Performance work requires perseverance
There are no magic bullets
Results are likely to change
Every V8 version brings changes
Performance varies wildly across versions
Religion is a culture of faith;
science is a culture of doubt.
— Richard Feynman?, physicist.
True Science teaches, above all,
to doubt and to be ignorant.
Miguel de Unamuno, philosopher.
Thanks! We're Hiring!
Building Efficient Software
By Alex Fernández