Dynamic Languages Strike Back. Steve Yegge Stanford EE Dept Computer Systems Colloquium May 7, 2008

Similar documents
CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CS 360 Programming Languages Interpreters

Introduction. CS 2210 Compiler Design Wonsun Ahn

Java On Steroids: Sun s High-Performance Java Implementation. History

Concepts of Programming Languages

CS558 Programming Languages

CSE 413 Spring Introduction to Ruby. Credit: Dan Grossman, CSE341

Design & Implementation Overview

Semantic Analysis. Lecture 9. February 7, 2018

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

CS558 Programming Languages

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

The Environment Model. Nate Foster Spring 2018

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

The Environment Model

Accelerating Ruby with LLVM

Forth Meets Smalltalk. A Presentation to SVFIG October 23, 2010 by Douglas B. Hoffman

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Environments

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Programming Languages 2nd edition Tucker and Noonan"

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Compilers. Prerequisites

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

The role of semantic analysis in a compiler

Adobe Flash Player ActionScript Virtual Machine (Tamarin)

Contents in Detail. Who This Book Is For... xx Using Ruby to Test Itself... xx Which Implementation of Ruby?... xxi Overview...

LESSON 13: LANGUAGE TRANSLATION

BEAMJIT, a Maze of Twisty Little Traces

What do Compilers Produce?

Safe Programming in Dynamic Languages Jeff Foster University of Maryland, College Park

Dynamically-typed Languages. David Miller

Know Your Engines How to Make Your JavaScript Fast

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 09/17/2015

Traditional Smalltalk Playing Well With Others Performance Etoile. Pragmatic Smalltalk. David Chisnall. August 25, 2011

Trace-based JIT Compilation

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

CSc 453 Interpreters & Interpretation

Sista: Improving Cog s JIT performance. Clément Béra

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

Intermediate Code, Object Representation, Type-Based Optimization

CS312: Programming Languages. Lecture 21: JavaScript

Optimising large dynamic code bases.

1DL321: Kompilatorteknik I (Compiler Design 1)

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 12 09/29/2016

Programming Languages, Summary CSC419; Odelia Schwartz

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

CS263: Runtime Systems Lecture: High-level language virtual machines

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

These are notes for the third lecture; if statements and loops.

Today. Continue our very basic intro to JavaScript. Lambda calculus

What is a programming language?

Static Program Analysis Part 1 the TIP language

Grading for Assignment #1

Introduction to Embedded Systems. Lab Logistics

Performance Per Watt. Native code invited back from exile with the Return of the King:

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

COMP 410 Lecture 1. Kyle Dewey

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

Optimizing Your Android Applications

Software. CPU implements "machine code" instructions. --Each machine code instruction is extremely simple. --To run, expanded to about 10 machine code

Just-In-Time Compilers & Runtime Optimizers

JavaScript and V8 A functional-ish language and implementation in the mainstream

Key components of a lang. Deconstructing OCaml. In OCaml. Units of computation. In Java/Python. In OCaml. Units of computation.

Identifying and Fixing Parameter Sniffing

Hello. I'm Deborah Kaplan, and I'm the co-lead of the accessibility team at open source blogging platform Dreamwidth.

Assigns a number to 110,000 letters/glyphs U+0041 is an A U+0062 is an a. U+00A9 is a copyright symbol U+0F03 is an

Dynamic Languages Toolkit. Presented by Andrey Tarantsov

Introduction to Mobile Development

Assumptions. History

JavaScript: the Big Picture

Weeks 6&7: Procedures and Parameter Passing

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Smalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)

More advanced CPUs. August 4, Howard Huang 1

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

Adaptive Optimization using Hardware Performance Monitors. Master Thesis by Mathias Payer

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

Scoping and Type Checking

Python Implementation Strategies. Jeremy Hylton Python / Google


JavaScript: Sort of a Big Deal,

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar

Slide Set 1 (corrected)

High-Performance and Parallel Computing

JSJS - Project Proposal

Types and Type Inference

CSE373: Data Structure & Algorithms Lecture 23: Programming Languages. Aaron Bauer Winter 2014

Transcription:

Dynamic Languages Strike Back Steve Yegge Stanford EE Dept Computer Systems Colloquium May 7, 2008

What is this talk about? Popular opinion of dynamic languages: Unfixably slow Not possible to create IDE-quality tools Maintenance traps at millions of LOC Is the popular opinion accurate? We ll look at the technology and see...

What do I mean by dynamic language? Eval, late-binding, runtime loading, mutable types, flexible dynamic dispatch,... Intentionally blurring dynamic typing and dynamic features for this talk! Hence: Perl, Python, Ruby, JavaScript, Lisp, Scheme, SmallTalk, Lua, Tcl...

But dynamism!= type tags (or lack thereof)! It s true: statically typed languages usually have some dynamic features Underlying problem is cultural: people think dynamic == dynamic typing == slow, bad tools Observation: techniques for creating tools for dynamic languages are similar to those for improving performance

So... why do we have dynamic languages? Stanford PhD candidate: I don t know why we have other langs. You only need C/C++. Well-known advantages to dynamic languages Productivity, expressiveness, flexibility,... Perceived downsides: speed, tools, and the ever-elusive maintainability

Why are dynamic languages slow? Hard to compile with traditional techniques Object & variable types can change Methods can be added/removed Target machine feature mismatches Lack of effort: scripting languages are I/O bound and haven t needed blinding speed

How can you speed up a dynamic language? Language-level improvements: Native threads, optional type system,... Virtual machine improvements: generational GC, special async I/O ops,... Smarter compilers!

Historical successes Common Lisp: native compilers, C-like speed StrongTalk: static types for SmallTalk Scheme: cross-compile into C & use GCC Self: type-feedback adaptive compilers Problem: they all sucked at marketing

Languages are no longer changing every 10 years Barrier to entry has gone up since 1994 Marketing obstacles (vs. Sun, Microsoft) Bar has gone up for tools & infrastructure Open source yielded lots of useful code Implication: we re stuck with what we ve got

Pigs attempts to fly Perl, Python: vanilla bytecode interpreters Ruby: interprets AST directly! (very slow) All: no usable concurrency options All: reference-count or mark-and-sweep GC Java proved pigs can reach interstellar space!

Intermission/Recap Yesterday s dynamic languages had great performance and great tools Today s dynamic languages: not so much Why aren t (more) people working to fix it? Ignorance, FUD and despair: not fixable! CS education failure: compilers courses!

Tooooooooooools Modern IDE expectations: autocomplete, jump-to-declaration, browsing, refactoring IntelliJ IDEA/JavaScript: autocomplete, jump-to-declaration, browse, refactoring,... What s missing? Not much! Java IDEs showed the way dynamic languages now playing catch-up

Tools: Syntax A language s syntax yields many static clues exploitable by IDEs. Consider: // what is the type of foo? function foo(a, b) { return a + b; } var bar = 17.6; // what is bar s type? var x = {a: hi, b: there }; // type of x?

Tools: Domain knowledge IDEs need to look for common idioms: function foo() {...} var foo = function() {...} foo = {a: function() {...}, b: function() {...}} foo.prototype.x = function() {...} with (foo) { x = function() {...} } Lots of work, but no more than doing Java name and type resolution

Tools: Inference var foo = new Object(); var x = foo; // how to determine that x.bar is foo.bar? x.bar = function() {...}; Alias inference is similar to flow-analysis In general: undecidable. In practice: 95+% Java IDEs also miss the ~5% reflection cases

Tools: Simulation/Emulation Common Java user complaint: dynamic IDEs need to run your program to be accurate Not feasible to load all the code! But Java runtime systems have monitoring, health checks, logging, dashboards, profiling... Notion that IDE must be separate from runtime is inaccurate in real-world scenarios

Dynamic tools: Summary Not harder to build than tools for static languages -- just different. Fundamental observation: most dynamic code isn t all that dynamic static analysis often possible bridge gap by running/simulating the code

Performance! Programmers bad at tedious automation but still prefer to hand-optimize code! Compilers/VMs continue to get smarter perf tricks keep getting obsoleted Cultural problem: micro-optimization requires less thought than actual design

Micro- vs. Global- Walter Bright: D slower than C++, but D programs faster than C++ programs Java: slower than C++ in benchmarks, often faster overall (esp. with multicore) Ruby on Rails: 20% faster than Struts, even though Ruby is way slower than Java Global optimizations always trump benchmarks!

Then are dynamic languages fast enough? Depends who you ask, and how you measure Many big systems in dynamic languages: Amazon.com, Yahoo, Orbitz, NYSE,... There s still value in improving performance: browser client apps increasingly complex server farms benefit from tiny perf gains

Case Study: JavaScript At a glance: Java-like syntax, prototype-based OOP lexical scoping, 1st-class functions, closures EcmaScript Edition 4: optional types Ajax caused surprise popularity surge Sudden focus on improving performance

JIT compilation (1 of 5) Trick #1: classic static type inference var x = 0; for (i=0; i<10; i++) x += i; sometimes possible to infer primitive ops and generate efficient machine code Problem: overflow changes type to Double (in JavaScript)

JIT compilation (2 of 5) Trick #2: Polymorphic Inline Caches (PICs) Developed at Stanford (Urs Hoelzle) permits inlining of polymorphic functions count receiver types at call sites make predictions from runtime counts 50% to 100% speedup of real-world code

JIT compilation (3 of 5) Trick #3: double-dispatch type inference box constants with virtual interfaces invoke operations like a+b in both directions (1st time): b.add(a), a.add(b) now you know exact types for variables inside loops, operands usually same type

JIT compilation (4 of 5) Trick #4: Trace trees targeted at loops, not methods! build up tree of runtime-compiled paths 1 path per operand type from same source result: massive basic block fall-through 20x speedups, and can be done in O(n) time! reports of 750x less time spent compiling

JIT compilation (5 of 5) Last trick for today: Escape analysis statically determine whether loop values escape the loop (used before or after) if not, can optimize away object allocations (including trace boxes) can save thousands of allocations in a single loop

JIT compilation: Recap How many of these tricks are there? Many! Underlying themes: Most CPU consumed in loop execution Runtime analysis yields smarter decisions Theoretical performance exceeds C++/static It s just a lot of work that few people do

Is JavaScript fast yet? Hard to measure; benchmarks controversial pure-javascript apps beginning to compete with the desktop HotRuby: Ruby VM in JS - 2x-5x faster!? Still tons of low-hanging fruit Trace trees, more JIT research, ES4,...

Beyond perf & tools If we solve perf and tools, what s left? Cranky programmers, ignorance, FUD maintainability - the ultimate FUD tool only solution: marketing, and lots of it Still several years of work left on perf/tools Static langs here for forseeable future!

What have we learned? We re stuck with today s popular languages Micro-optimization best done by software Recent dynamic language compilation revival Tools/performance very possible, lots of work Nothing matters without marketing!

Q&A