This document discusses the phc compiler for PHP. It begins with an introduction and motivation for compiling PHP. It then outlines the current state of phc, including challenges to compilation and phc's solution of using the PHP C API. The document discusses next steps for phc, including simple and advanced optimizations. It concludes by discussing experiences with using phc to compile PHP code.
Python uses DYNAMIC typing AND A COMBINATION of reference counting AND A cycle-detecting GARBAGE collector for memory MANAGEMENT. It ALSO FEATURES DYNAMIC NAME RESOLUTION(LATE binding) which binds methods AND VARIABLE NAMES during PROGRAM execution.
As we know, whenever we run ANY APPLICATION it gets LOADED into RAM AND some memory gets ALLOCATED by OS for THAT APPLICATION.
Learn more about Python PRogramming with Learnbay.
Visit:https://www.learnbay.co/data-science-course/
The document describes a Python module called WAD that converts fatal extension errors in Python extensions into Python exceptions. This makes debugging Python extensions easier by providing more contextual information about errors in extensions from within the Python interpreter. The module works by wrapping C/C++ extension functions in try/catch blocks and converting caught signals and assertions into Python exceptions.
Lutz Böhne presents Pandora's Bochs, an automated unpacker implemented using the open-source Bochs emulator. It instruments Bochs to monitor processes for behaviors indicative of unpacking, such as memory writes and branches. When such behaviors are seen, it dumps memory regions to reconstruct unpacked code and valid PE files. The system identifies processes using CR3 registers and terminates monitoring based on lack of "innovation" over time. This allows automated dynamic analysis of runtime packers without access to source code.
This document provides information on reading from and writing to files in C programming. It discusses opening files with fopen(), reading and writing single characters with fgetc() and fputc(), reading and writing lines with fgets() and fputs(), closing files with fclose(), and performing random access in files. It also includes examples and practice problems.
Detecting Occurrences of Refactoring with Heuristic SearchShinpei Hayashi
This document describes a technique for detecting refactorings between two versions of a program using heuristic search. Refactorings are detected by generating intermediate program states through applying refactorings, and finding a path from the original to modified program that minimizes differences. Structural differences are used to identify likely refactorings. Candidate refactorings are evaluated and applied to generate new states, with the search terminating when the state matches the modified program. A supporting tool was developed and a case study found the technique could correctly detect an actual series of refactorings between program versions.
SWIG (Simplified Wrapper and Interface Generator) is a tool that connects programs written in C/C++ with scripting languages like Perl, Python, Ruby and Tcl. It works by reading interface definition files that describe functions and variables in a C/C++ library and generating wrapper code that allows these functions and variables to be accessed from a scripting language. SWIG handles much of the complexity of interfacing C/C++ code with other languages. It allows prototyping and debugging integration between different systems and simplifies building extension modules for languages like Perl.
Python uses DYNAMIC typing AND A COMBINATION of reference counting AND A cycle-detecting GARBAGE collector for memory MANAGEMENT. It ALSO FEATURES DYNAMIC NAME RESOLUTION(LATE binding) which binds methods AND VARIABLE NAMES during PROGRAM execution.
As we know, whenever we run ANY APPLICATION it gets LOADED into RAM AND some memory gets ALLOCATED by OS for THAT APPLICATION.
Learn more about Python PRogramming with Learnbay.
Visit:https://www.learnbay.co/data-science-course/
The document describes a Python module called WAD that converts fatal extension errors in Python extensions into Python exceptions. This makes debugging Python extensions easier by providing more contextual information about errors in extensions from within the Python interpreter. The module works by wrapping C/C++ extension functions in try/catch blocks and converting caught signals and assertions into Python exceptions.
Lutz Böhne presents Pandora's Bochs, an automated unpacker implemented using the open-source Bochs emulator. It instruments Bochs to monitor processes for behaviors indicative of unpacking, such as memory writes and branches. When such behaviors are seen, it dumps memory regions to reconstruct unpacked code and valid PE files. The system identifies processes using CR3 registers and terminates monitoring based on lack of "innovation" over time. This allows automated dynamic analysis of runtime packers without access to source code.
This document provides information on reading from and writing to files in C programming. It discusses opening files with fopen(), reading and writing single characters with fgetc() and fputc(), reading and writing lines with fgets() and fputs(), closing files with fclose(), and performing random access in files. It also includes examples and practice problems.
Detecting Occurrences of Refactoring with Heuristic SearchShinpei Hayashi
This document describes a technique for detecting refactorings between two versions of a program using heuristic search. Refactorings are detected by generating intermediate program states through applying refactorings, and finding a path from the original to modified program that minimizes differences. Structural differences are used to identify likely refactorings. Candidate refactorings are evaluated and applied to generate new states, with the search terminating when the state matches the modified program. A supporting tool was developed and a case study found the technique could correctly detect an actual series of refactorings between program versions.
SWIG (Simplified Wrapper and Interface Generator) is a tool that connects programs written in C/C++ with scripting languages like Perl, Python, Ruby and Tcl. It works by reading interface definition files that describe functions and variables in a C/C++ library and generating wrapper code that allows these functions and variables to be accessed from a scripting language. SWIG handles much of the complexity of interfacing C/C++ code with other languages. It allows prototyping and debugging integration between different systems and simplifies building extension modules for languages like Perl.
Android applications are an interesting target for
reverse engineering. They are written in Java, which is tradi-
tionally good to decompile and are executed by Google’s custom
Java virtual machine, making them interesting to study. In this
paper we present the basic methods and approaches as well as
the necessary tools to reverse engineer Android applications. We
discuss how to change Android applications and show alternative
approaches including man-in-the-middle attacks and automation.
This document discusses machine learning on source code. It begins by defining machine learning on source code as applying machine learning where the input data is source code. It then discusses some of the challenges of applying machine learning to source code, including data retrieval and analysis. Finally, it provides examples of potential use cases like predicting the next token in code, learning to represent programs with graphs, and building tools to assist with code reviews.
PHP's languages run on a server-side scripting platform. It’s used for making powerful dynamic and interactive Websites. This is a broadly free, well-organized, and alternative to competitors such as Microsoft ASP.
The document discusses metaprogramming in Ruby and domain specific languages (DSLs). It provides examples of metaprogramming in programs like the Java compiler and Ruby interpreter. It also shows how DSLs are used to define languages for specific domains like musical notes or guitar chords. The presentation introduces metaprogramming and DSL implementation, including changing self, missing constants/methods, and custom operators.
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...Shinpei Hayashi
This document proposes an annotation-based approach to recording finer-grained software evolution using an IDE. Developers can classify their edit operations according to different modes, and the system structures the edits to generate source code deltas for each intentional change. A prototype implementation as an Eclipse plug-in automates reordering edits based on the modes. This approach aims to avoid mixed changesets and better capture the relationships between changes.
The document discusses how the Java Virtual Machine (JVM) supports dynamic languages through the invokedynamic bytecode instruction. This simplifies the implementation of compilers and runtime systems for dynamically typed languages on the JVM by allowing method dispatch to be deferred until runtime. It also describes how method handles in Java 7 provide a more efficient and flexible way to access methods compared to reflection by embedding access restrictions and allowing faster invocation and combination of methods.
This document provides an overview of the Python programming language. It discusses that Python is an easy to use, open-source scripting language (3 sentences or less).
This document provides a quick introduction to the C programming language. It discusses basic C syntax like main functions, header files, comments, and variables. It also covers data types, memory, functions, scopes, expressions, control flow statements like if/else and loops. Functions can access arguments and global variables from their own scope but not variables from outer scopes unless passing their addresses.
Generating Assertion Code from OCL: A Transformational Approach Based on Simi...Shinpei Hayashi
This document presents an approach for generating assertion code from the Object Constraint Language (OCL) using model transformations. The approach constructs a hierarchy of programming languages based on their structural similarities. This allows rules for translating OCL to be reused across multiple implementation languages, saving approximately 50% of the effort compared to creating individual translators. An evaluation implemented the approach in Maude and demonstrated its ability to generate code for Java, Python, Haskell and O'Haskell from a single OCL specification.
The document discusses increasing the efficiency of a web container by using asynchronous calls. It begins with an introduction of the speaker and their background in Java development. It then covers topics like Web 2.0, asynchronous web technologies, Servlet 3.0 specifications, and provides a demo comparing synchronous vs. asynchronous requests. The document discusses how asynchronous processing can help with long-running requests and real-time updates. It provides examples of using asynchronous contexts and executor frameworks in Java to handle asynchronous tasks.
The document discusses how changes to Java libraries can affect compatibility with client programs. It explores how modifying interfaces, method signatures, static vs non-static methods, and other changes impact both binary and source compatibility. A series of examples are provided where a library evolves from version 1.0 to 2.0. For each change, it analyzes whether the client program will still compile and run correctly.
Sentence-to-Code Traceability Recovery with Domain OntologiesShinpei Hayashi
The document describes a technique for recovering traceability between natural language sentences and source code using domain ontologies. An automated tool was implemented and evaluated on a case study using the JDraw software. Results showed the technique worked well, recovering traceability between 7 sentences and code with higher accuracy than without using the ontology. The ontology helped improve recall and detect traceability in cases where word similarity alone did not work well. Future work is needed to evaluate on larger cases and domains.
This document discusses using PGQ (a PostgreSQL queuing solution) to improve the reliability of batch processing jobs. It outlines the needs for reliable, monitored batches and then describes how PGQ features like its producer/consumer model and APIs can be used to implement robust daemon processes to handle batch jobs. Code examples are provided for consuming events from PGQ queues in PHP to integrate existing models and processes batches as daemon jobs.
Python always got a good relation with the C language, through its syntax affinity or with its own API integrated with C.
Presentation's goal is to describe and compare several ways of doing bindings in C/C++ for Python which allow to augment Python features through speed improvements or giving access to a large ecosystem of C/C++ (or other) libs.
Following is presented : Python C API, ctypes, SWIG, Cython speaking about qualities and weak points.
Both Python and PHP are interpreted scripting languages popular for web applications due to facilitating rapid prototyping. They are both open source and can run on almost all platforms without recompilation, making them extremely portable. PHP is more commonly used for web development as it can be directly implemented in HTML files and has more resources. However, Python requires understanding additional technologies like CGI and WSGI to use for web applications.
The document discusses various Python tips and tricks. It covers topics like *args and **kwargs, debugging with pdb, generators, map filter and reduce functions, set data structure, ternary operators, decorators, global and return statements, mutation, __slots__ magic, virtual environments, collections, enumerate, zip and unzip functions, object introspection, comprehensions, exceptions, classes, lambdas, one-liners, for/else loop, Python C extensions, open function, targeting Python 2+3, coroutines, function caching, and context managers. The document is intended as a reference for intermediate and advanced Python programmers to learn additional useful concepts.
The document discusses extending the PHP Development Toolkit (PDT) in Eclipse. It provides examples of how to extend PDT by registering build participants and AST visitors to integrate validation rules. Quick fixes can also be added to automatically fix problems. The document recommends using Eclipse's JavaScript support to dynamically extend PDT through scripting instead of Java for PHP developers. This allows customizing PDT distributions and potentially writing PHP plugins in PHP.
This document discusses concepts related to living a fulfilling life through creativity and flow. It is divided into four sections: Discovery, discussing seeing with new eyes; Resistance, about overcoming obstacles to creative pursuits; Flow, explaining how flow states provide the most happiness; and Engagement, emphasizing managing one's energy across different domains. The overall message encourages finding fulfillment through creative challenges that match one's skills.
The document discusses perseverance in the face of adversity using birds as an example. It notes how birds will rebuild their nests repeatedly until they are able to lay eggs, even after storms or animals destroy their work. It encourages the reader by saying that even though life can strike you down, you should pray, have hope, and rebuild your life so that it runs well again. The key message is to not shrink back but keep moving forward despite challenges, and to never stop singing.
The document discusses various topics related to systems building including testing code frequently, tribes throughout history, clouds and evolution. It mentions cracking the crystal of truth and using code to build infrastructure. The document encourages using one's powers for awesome and ends by providing contact information for questions.
Android applications are an interesting target for
reverse engineering. They are written in Java, which is tradi-
tionally good to decompile and are executed by Google’s custom
Java virtual machine, making them interesting to study. In this
paper we present the basic methods and approaches as well as
the necessary tools to reverse engineer Android applications. We
discuss how to change Android applications and show alternative
approaches including man-in-the-middle attacks and automation.
This document discusses machine learning on source code. It begins by defining machine learning on source code as applying machine learning where the input data is source code. It then discusses some of the challenges of applying machine learning to source code, including data retrieval and analysis. Finally, it provides examples of potential use cases like predicting the next token in code, learning to represent programs with graphs, and building tools to assist with code reviews.
PHP's languages run on a server-side scripting platform. It’s used for making powerful dynamic and interactive Websites. This is a broadly free, well-organized, and alternative to competitors such as Microsoft ASP.
The document discusses metaprogramming in Ruby and domain specific languages (DSLs). It provides examples of metaprogramming in programs like the Java compiler and Ruby interpreter. It also shows how DSLs are used to define languages for specific domains like musical notes or guitar chords. The presentation introduces metaprogramming and DSL implementation, including changing self, missing constants/methods, and custom operators.
Recording Finer-Grained Software Evolution with IDE: An Annotation-Based Appr...Shinpei Hayashi
This document proposes an annotation-based approach to recording finer-grained software evolution using an IDE. Developers can classify their edit operations according to different modes, and the system structures the edits to generate source code deltas for each intentional change. A prototype implementation as an Eclipse plug-in automates reordering edits based on the modes. This approach aims to avoid mixed changesets and better capture the relationships between changes.
The document discusses how the Java Virtual Machine (JVM) supports dynamic languages through the invokedynamic bytecode instruction. This simplifies the implementation of compilers and runtime systems for dynamically typed languages on the JVM by allowing method dispatch to be deferred until runtime. It also describes how method handles in Java 7 provide a more efficient and flexible way to access methods compared to reflection by embedding access restrictions and allowing faster invocation and combination of methods.
This document provides an overview of the Python programming language. It discusses that Python is an easy to use, open-source scripting language (3 sentences or less).
This document provides a quick introduction to the C programming language. It discusses basic C syntax like main functions, header files, comments, and variables. It also covers data types, memory, functions, scopes, expressions, control flow statements like if/else and loops. Functions can access arguments and global variables from their own scope but not variables from outer scopes unless passing their addresses.
Generating Assertion Code from OCL: A Transformational Approach Based on Simi...Shinpei Hayashi
This document presents an approach for generating assertion code from the Object Constraint Language (OCL) using model transformations. The approach constructs a hierarchy of programming languages based on their structural similarities. This allows rules for translating OCL to be reused across multiple implementation languages, saving approximately 50% of the effort compared to creating individual translators. An evaluation implemented the approach in Maude and demonstrated its ability to generate code for Java, Python, Haskell and O'Haskell from a single OCL specification.
The document discusses increasing the efficiency of a web container by using asynchronous calls. It begins with an introduction of the speaker and their background in Java development. It then covers topics like Web 2.0, asynchronous web technologies, Servlet 3.0 specifications, and provides a demo comparing synchronous vs. asynchronous requests. The document discusses how asynchronous processing can help with long-running requests and real-time updates. It provides examples of using asynchronous contexts and executor frameworks in Java to handle asynchronous tasks.
The document discusses how changes to Java libraries can affect compatibility with client programs. It explores how modifying interfaces, method signatures, static vs non-static methods, and other changes impact both binary and source compatibility. A series of examples are provided where a library evolves from version 1.0 to 2.0. For each change, it analyzes whether the client program will still compile and run correctly.
Sentence-to-Code Traceability Recovery with Domain OntologiesShinpei Hayashi
The document describes a technique for recovering traceability between natural language sentences and source code using domain ontologies. An automated tool was implemented and evaluated on a case study using the JDraw software. Results showed the technique worked well, recovering traceability between 7 sentences and code with higher accuracy than without using the ontology. The ontology helped improve recall and detect traceability in cases where word similarity alone did not work well. Future work is needed to evaluate on larger cases and domains.
This document discusses using PGQ (a PostgreSQL queuing solution) to improve the reliability of batch processing jobs. It outlines the needs for reliable, monitored batches and then describes how PGQ features like its producer/consumer model and APIs can be used to implement robust daemon processes to handle batch jobs. Code examples are provided for consuming events from PGQ queues in PHP to integrate existing models and processes batches as daemon jobs.
Python always got a good relation with the C language, through its syntax affinity or with its own API integrated with C.
Presentation's goal is to describe and compare several ways of doing bindings in C/C++ for Python which allow to augment Python features through speed improvements or giving access to a large ecosystem of C/C++ (or other) libs.
Following is presented : Python C API, ctypes, SWIG, Cython speaking about qualities and weak points.
Both Python and PHP are interpreted scripting languages popular for web applications due to facilitating rapid prototyping. They are both open source and can run on almost all platforms without recompilation, making them extremely portable. PHP is more commonly used for web development as it can be directly implemented in HTML files and has more resources. However, Python requires understanding additional technologies like CGI and WSGI to use for web applications.
The document discusses various Python tips and tricks. It covers topics like *args and **kwargs, debugging with pdb, generators, map filter and reduce functions, set data structure, ternary operators, decorators, global and return statements, mutation, __slots__ magic, virtual environments, collections, enumerate, zip and unzip functions, object introspection, comprehensions, exceptions, classes, lambdas, one-liners, for/else loop, Python C extensions, open function, targeting Python 2+3, coroutines, function caching, and context managers. The document is intended as a reference for intermediate and advanced Python programmers to learn additional useful concepts.
The document discusses extending the PHP Development Toolkit (PDT) in Eclipse. It provides examples of how to extend PDT by registering build participants and AST visitors to integrate validation rules. Quick fixes can also be added to automatically fix problems. The document recommends using Eclipse's JavaScript support to dynamically extend PDT through scripting instead of Java for PHP developers. This allows customizing PDT distributions and potentially writing PHP plugins in PHP.
This document discusses concepts related to living a fulfilling life through creativity and flow. It is divided into four sections: Discovery, discussing seeing with new eyes; Resistance, about overcoming obstacles to creative pursuits; Flow, explaining how flow states provide the most happiness; and Engagement, emphasizing managing one's energy across different domains. The overall message encourages finding fulfillment through creative challenges that match one's skills.
The document discusses perseverance in the face of adversity using birds as an example. It notes how birds will rebuild their nests repeatedly until they are able to lay eggs, even after storms or animals destroy their work. It encourages the reader by saying that even though life can strike you down, you should pray, have hope, and rebuild your life so that it runs well again. The key message is to not shrink back but keep moving forward despite challenges, and to never stop singing.
The document discusses various topics related to systems building including testing code frequently, tribes throughout history, clouds and evolution. It mentions cracking the crystal of truth and using code to build infrastructure. The document encourages using one's powers for awesome and ends by providing contact information for questions.
This presentation is a preparation for PHP Test Fest 2009 (http://qa.php.net/testfest). See your local PHP user group for details of this world wide event.
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)Mark Niebergall
The document discusses automatic compatibility checking for PHP 7 using the php7cc and PHPCompatibility tools. It provides an overview of why upgrading to PHP 7 is important for performance, security and new features. It then demonstrates how to use the php7cc and PHPCompatibility tools to identify compatibility issues, including various configuration options. Common issues that can be missed by static analysis like test coverage are also discussed. An analysis of a PHP codebase found errors and warnings using both tools.
Paweł Skotnicki: Masz zacząć pracę z legacy code? Nie wiesz, gdzie najlepiej zrobić refactor? A może zaczynasz nowy projekt, który, tym razem, ma utrzymywać najwyższą jakość kodu? Istnieje sporo narzędzi, które mają w tym pomóc, a my często o nich zapominamy. Przedstawię lub przypomnę część z nich.
The document provides information about upcoming PHP mentorship opportunities with LaunchCode in September, PHP security updates, conferences, and features. It summarizes:
- Mentorship opportunities on September 8th and 10th to provide feedback on student projects through LaunchCode.
- Recommendations to upgrade PHP versions due to security fixes, including PHP 7.0.10, 5.6.25, and 5.5.38.
- Upcoming features in PHP 7.1 including new functions like session_create_id() and changes to session IDs, signals, and random number generation.
- Various PHP conferences happening in late 2016 and early 2017, including Midwest.io, Pacific Northwest PHP
The document discusses code metrics that can be used to evaluate code quality in PHP projects. It introduces various metrics like lines of code, test coverage, cyclomatic complexity, coupling metrics, lack of cohesion in methods, Halstead complexity measures, and maintainability index. It recommends always using tools like PHP Code Sniffer and PHPUnit for testing and recommends adopting tools like PHPSpec, Behat, PHP Copy/Paste Detector and PHPMetrics. It also suggests giving tools like Humbug for mutant testing a try and considering SaaS options with customization efforts.
Zoe Slattery's slides from PHPNW08:
The ability to store large quantities of local data means that many applications require some form of text search and retrieval facility. From the point of view of the application developer there are a number of choices to make, the first is whether to use a complete packaged solution or whether to use one of the available information libraries to build a custom information retrieval (IR) solution. In this talk I’ll look at the options for PHP programmers who choose to embed IR facilities within their applications.
For Java programmers there is clearly a good range of options for text retrieval libraries, but options for PHP programmers are more limited. At first sight for a PHP programmer wishing to embed indexing and search facilities in their application, the choice seems obvious - the PHP implementation of Lucene (Zend Search Lucene). There is no requirement to support another language, the code is PHP therefore easy for PHP programmers to work with and the license is commercially friendly. However, whilst ease of integration and support are key factors in choice of technology, performance can also be important; the performance of the PHP implementation of Lucene is poor compared to the Java implementation.
In this talk I’ll explain the differences in performance between PHP implementation of Lucene and the Java implementation and examine the other options available to PHP programmers for whom performance is a critical factor.
Kyrylo Cherneha "C++ & Python Interaction in Automotive Industry"LogeekNightUkraine
The document discusses using Python for testing C++ code. It provides an agenda that covers QA vs developers, testing frameworks/tools/libraries like Boost.Python and Pybind11. Pybind11 is highlighted as a modern alternative to Boost.Python for binding C++ and Python, offering features like custom data structures, methods, exceptions and STL support with correct reference counting. The conclusion is that Python is useful for tasks like parsing files and providing shell/OS functionality when working with C++.
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Fwdays
PHP at Scale: Knowing enough to be dangerous! by Oleksii Petrov discusses how to scale PHP applications. It covers strategies like caching, queueing, read/write splitting, and sharding. It also discusses using load balancers and choosing the right database. The key is to improve system metrics without dramatically changing the system. Scaling is predefined by your stack and architecture. Performance comes from optimizations everywhere, not just PHP. Being distributed is very challenging.
The document is a presentation on high performance PHP. It discusses profiling PHP applications to identify bottlenecks, code-level optimizations that can provide gains, and big wins like upgrading PHP versions and using APC correctly. It also covers load testing tools like JMeter and key takeaways like focusing on big wins and caching.
This document provides an overview of the Phalcon PHP framework. It discusses why frameworks are important for PHP development and how traditional frameworks work. It then explains how Phalcon is different as it is implemented as a PHP extension written in C, making it faster than traditional frameworks. The document demonstrates how to install Phalcon, create a basic project structure, define controllers and models, and connect to a database.
Php through the eyes of a hoster phpbnl11Combell NV
The document discusses PHP from the perspective of a web hosting provider. It covers topics like installing PHP from source or using package managers, different PHP APIs like FastCGI and CLI, PHP configuration options and their security implications, PHP versions and features like PEAR and PECL, why PHP attracts many developers both skilled and unskilled, common security issues and their true causes, and scaling PHP applications by scaling up or out.
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Edureka!
This document discusses loops in Python. It begins by explaining why loops are useful, such as for payroll processing to calculate salaries and bonuses for multiple employees. It then defines loops as allowing code to execute repeatedly based on conditional statements. The document outlines the main types of loops in Python - while loops, for loops, and nested loops. While loops iterate until a condition is false, for loops iterate a specified number of times, and nested loops involve loops within other loops. Examples are provided for each loop type, such as a guessing game to demonstrate a while loop and calculating factorials with a for loop.
This document discusses PHP from the perspective of a web hosting provider. It covers PHP installation and configuration options like Apache modules, FastCGI, and PHP-FPM. It also discusses PHP versions, extensions, frameworks, and configuration settings and their impact on security and performance. The hosting provider has the same goals as developers - to ensure applications work, perform, scale, are secure and available.
PHP 5.4 - Begin your love affair with traitsGraham Weldon
This document discusses PHP 5.4 and introduces new features such as traits, array dereferencing, binary notation, and upload progress tracking. It provides examples of using traits to reuse code across classes without complicated inheritance. Traits allow for small reusable code sections that can be included in any class while maintaining a precedence order. The document encourages early adoption of new PHP versions for cleaner code and new language features, while also advising testing before deploying to production.
Ein Stall voller Trüffelschweine - (PHP-)Profiling-Tools im Überblickrenebruns
An overview of PHP profiling tools was presented. The presentation began with an introduction to profiling and why it is useful for developers. Common issues that can be identified through profiling like slow JavaScript code, high memory usage, and inefficient database queries were discussed. Tools for profiling at the browser, frontend, backend, and database level were then covered in detail including Chrome DevTools, Xdebug, XHProf, and using EXPLAIN queries. The presentation concluded with best practices for profiling like starting broadly and narrowing down the issue, verifying optimizations worked, and using benchmarks like Apache Benchmark.
PHP Meetup
Дмитро Карпович
5 років як Full Stack Web-Developer. Пише на чому попаде і де попаде )
Презентація про досвід використання технологій, кращих сервісів та бібліотек, які суттєво полегшують життя розробника
Practical tips for dealing with projects involving legacy code. Covers investigating past projects, static analysis of existing code, and methods for changing legacy code.
Presented at PHP Benelux '10
With PHP 8.0 recently released and PHP 5.x still accounting for over 40% of all production environments, it's time to paint a clear picture on not just why everyone should move to 8.x, but on how to get code ready for the latest version of PHP. In this talk, we'll look at some handy tools and techniques to ease the migration.
This document provides information about TestFest 2009 which was held in Utrecht, Netherlands. It discusses testing PHP code through .phpt files which contain test cases that are run individually. Guidelines are provided for writing good test cases, such as testing one feature per file and avoiding large outputs. Resources for learning more about PHP testing and code coverage analysis are listed at the end.
Thijs Feryn gave a presentation on the CLI SAPI at the PHPBarcelona Conference on October 28th, 2011. He discussed how the CLI SAPI allows PHP scripts to be executed from the command line interface and when it is useful, such as for cron jobs, batch tasks, daemons and more. He provided examples of passing arguments, reading from STDIN, and using functions like getopt in CLI scripts.
Similar to Compiling And Optimizing Scripting Languages (20)
Wii Ruby All Work And No Play Just Wont DoLittleBIGRuby
This document discusses using a Wii remote with Ruby code to create interactive programs. It provides an overview of the necessary hardware, libraries for connecting to the Wii remote from Ruby like WiiUseJRuby, and the Monkeybars GUI library. It also demonstrates example code for mapping button presses and motion data to methods, and includes demos of using the Wii remote for MIDI music and motion plotting. The document encourages an exploratory approach to programming with the Wii remote.
The document discusses the building blocks of modularity, including different types of connascence (ways that software elements are connected) such as connascence of name, position, meaning, algorithm, and execution. It advocates applying principles like the rule of locality, degree, and DRY (don't repeat yourself) to reduce strong connascence and increase loose coupling between modules. This improves modularity, reusability, and maintainability of software designs.
The document discusses Rack, a modular web server interface for Ruby that allows web applications and frameworks to be written as middleware stacks. It covers topics like Rack applications as middleware, common Rack middleware components, building applications with Rack and middleware, and integrating Rack middleware with frameworks like Rails.
The document discusses outside-in development and behavior-driven development techniques. It provides examples of writing feature files with scenarios and steps, and creating corresponding step definitions to define the behavior. It also discusses structuring the test code, using fixtures/factories, and integrating with testing frameworks. The overall process involves writing scenarios, defining pending steps, implementing step definitions, refactoring code, and repeating.
Practical Puppet Systems Building Systems 1LittleBIGRuby
The document discusses various topics related to systems building including testing code frequently, tribes throughout history, clouds and evolution. It mentions cracking the crystal of truth and using code to build infrastructure. The document provides encouragement to use powers for awesome and asks if there are any questions. Contact information is provided at the end.
This document provides an overview and introduction to code reading skills and the RestClient library. It discusses why code reading is an important skill, introduces RestClient as a library for making HTTP requests, and provides examples of using RestClient to interact with Twitter's API. It also summarizes some other Ruby libraries and concepts discussed in the document like CSV, threading, and signal handling.
The document discusses using Foreign Function Interface (FFI) to extend Ruby with C code. It describes defining a C struct for metrics similar to a Ruby Metric class, then binding the C functions that operate on the struct to Ruby via FFI. This allows metrics calculated by the C code to be accessed from Ruby while retaining performance compared to a pure Ruby implementation.
This document provides an overview of Sequel, a Ruby ORM and database toolkit. It discusses Sequel's history and key features, including database support, datasets, models, associations, and eager loading. Sequel aims to provide a clean Ruby API for building queries and interacting with databases while avoiding complexity where possible. It emphasizes features like connection pooling, functional-style datasets, and explicit association methods over proxies.
1. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Compiling and Optimizing Scripting Languages
Paul Biggar and David Gregg
Department of Computer Science and Statistics
Trinity College Dublin
Google, 18th March, 2009
Trinity College Dublin 1
2. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Motivation
User needs web page in 0.5 seconds
Execution time
DB access
Network latency
Browser rendering
Easier maintainance
What if execution was:
2x as fast?
10x as fast?
Trinity College Dublin 2
3. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 3
4. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 4
5. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
phc
http://phpcompiler.org
Ahead-of-time compiler for PHP
Edsko de Vries, John Gilbert, Paul Biggar
BSD license
Latest release: 0.2.0.3 - compiles non-OO
svn trunk: compiles most OO
Trinity College Dublin 5
6. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Structure of phc
Trinity College Dublin 6
7. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
PHP
<?php
echo quot;helloquot;, quot;world!quot;;
?>
Trinity College Dublin 7
8. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
AST
PHP_script
List<Statement>
Eval_expr (3) Nop (5)
Method_invocation (3)
NULL
METHOD_NAME (3) List<Actual_parameter>
(Target)
echo Actual_parameter (3) Actual_parameter (3)
STRING (3) STRING (3)
hello world!
Trinity College Dublin 8
9. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
HIR
<?php
$x = $a + $b + $c + $d;
?>
<?php
$TLE0 = ($a + $b);
$TLE1 = ($TLE0 + $c);
$x = ($TLE1 + $d);
?>
Trinity College Dublin 9
10. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
MIR
<?php
while ($cond)
echo quot;helloquot;, quot;world!quot;;
?>
<?php
L7:
$TLE0 = !$cond;
if ($TLE0) goto L3 else goto L6;
L6:
print(’hello’);
print(’world!’);
goto L7;
L3:
?>
Trinity College Dublin 10
11. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Plugins
http://phpcompiler.org/doc/latest/devmanual.html
Trinity College Dublin 11
12. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
XML
<?xml version=quot;1.0quot;?>
<AST:PHP_script xmlns:AST=quot;http://www.phpcompiler.org/phc-1.1quot;>
<AST:Statement_list>
<AST:Eval_expr>
<AST:Method_invocation>
<AST:Target xsi:nil=quot;truequot; />
<AST:METHOD_NAME>
<value>echo</value>
</AST:METHOD_NAME>
<AST:Actual_parameter_list>
<AST:Actual_parameter>
<bool><!-- is_ref -->false</bool>
<AST:STRING>
<value>hello</value>
</AST:STRING>
</AST:Actual_parameter>
<AST:Actual_parameter>
<bool><!-- is_ref -->false</bool>
<AST:STRING>
<value>world!</value>
</AST:STRING>
</AST:Actual_parameter>
</AST:Actual_parameter_list>
</AST:Method_invocation>
</AST:Eval_expr>
<AST:Nop>
</AST:Nop>
</AST:Statement_list>
</AST:PHP_script>
Trinity College Dublin 12
13. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 13
14. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
SAC 2009
A Practical Solution for Scripting Language
Compilers
Paul Biggar, Edsko de Vries and David Gregg
Department of Computer Science and Statistics
Trinity College Dublin
ACM Symposium on Applied Computing - PL track
12th March, 2009
Trinity College Dublin 14
15. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Sneak peak
Problem: Scripting languages present “unique” problems
(in practice)
Solution: Re-use as much of the Canonical Reference
Implementation as possible.
Trinity College Dublin 15
16. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 16
17. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Undefined
The PHP group claim that they have the final say in
the specification of PHP. This group’s specification is
an implementation, and there is no prose specification
or agreed validation suite. There are alternate
implementations [...] that claim to be compatible (they
don’t say what this means) with some version of PHP.
D. M. Jones. Forms of language specification: Examples from
commonly used computer languages. ISO/IEC
JTC1/SC22/OWG/N0121, February 2008.
Trinity College Dublin 17
18. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Batteries included
Jeff Atwood, Coding Horror, May 20th, 2008
http://www.codinghorror.com/blog/archives/001119.html
Trinity College Dublin 18
19. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Change between releases
<?php
var_dump (0x9fa0ff0b);
?>
PHP 5.2.1 (32-bit)
int(2147483647)
PHP 5.2.3 (32-bit)
float(2678128395)
Trinity College Dublin 19
20. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Run-time code generation
<?php
eval ($argv[1]);
?>
<?php
include (quot;mylib.phpquot;);
...
include (quot;plugin.phpquot;);
...
?>
Trinity College Dublin 20
21. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 21
22. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Use C API
Trinity College Dublin 22
23. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
More detail
PHP zval
Python PyObject
Ruby VALUE
Lua TValue
H. Muhammad and R. Ierusalimschy. C APIs in extension and
extensible languages. Journal of Universal Computer Science,
13(6):839–853, 2007.
Trinity College Dublin 23
24. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Simple listings: $i = 0
// $i = 0;
{
zval* p_i;
php_hash_find (LOCAL_ST, quot;iquot;, 5863374, p_i);
php_destruct (p_i);
php_allocate (p_i);
ZVAL_LONG (*p_i, 0);
}
Trinity College Dublin 24
25. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Example: $i = 0
// $i = 0;
{
if (local_i == NULL)
{
local_i = EG (uninitialized_zval_ptr);
local_i->refcount++;
}
zval **p_lhs = &local_i;
zval *value;
if ((*p_lhs)->is_ref)
{
// Always overwrite the current value
value = *p_lhs;
zval_dtor (value);
}
else
{
ALLOC_INIT_ZVAL (value);
zval_ptr_dtor (p_lhs);
*p_lhs = value;
}
ZVAL_LONG (value, 0);
}
Trinity College Dublin 25
26. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Example: $i = $j
// $i = $j;
{
if (local_i == NULL)
{
local_i = EG (uninitialized_zval_ptr);
local_i->refcount++;
}
zval **p_lhs = &local_i;
zval *rhs;
if (local_j == NULL)
rhs = EG (uninitialized_zval_ptr);
else
rhs = local_j;
if (*p_lhs != rhs)
{
if ((*p_lhs)->is_ref)
{
// First, call the destructor to remove any data structures
// associated with lhs that will now be overwritten
zval_dtor (*p_lhs);
// Overwrite LHS
(*p_lhs)->value = rhs->value;
(*p_lhs)->type = rhs->type;
zval_copy_ctor (*p_lhs);
}
else
{
zval_ptr_dtor (p_lhs);
if (rhs->is_ref)
{
// Take a copy of RHS for LHS
*p_lhs = zvp_clone_ex (rhs);
}
else
{
// Share a copy
rhs->refcount++;
*p_lhs = rhs;
}
}
}
Trinity College Dublin 26
}
27. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Example: printf ($f)
static zend_fcall_info printf_fci;
static zend_fcall_info_cache printf_fcic = { 0, NULL, NULL, NULL };
// printf($f);
{
if (!printf_fcic->initialized)
{
zval fn;
INIT_PZVAL (&fn);
ZVAL_STRING (&fn, quot;printfquot;, 0);
int result = zend_fcall_info_init (&fn, &printf_fci, &printf_fcic TSRMLS_CC);
if (result != SUCCESS)
{
phc_setup_error (1, quot;listings_source.phpquot;, 8, NULL TSRMLS_CC);
php_error_docref (NULL TSRMLS_CC, E_ERROR,
quot;Call to undefined function %s()quot;, function_name);
}
}
zend_function *signature = printf_fcic.function_handler;
zend_arg_info *arg_info = signature->common.arg_info; // optional
int by_ref[1];
int abr_index = 0;
// TODO: find names to replace index
if (arg_info)
{
by_ref[abr_index] = arg_info->pass_by_reference;
arg_info++;
}
else
by_ref[abr_index] = signature->common.pass_rest_by_reference;
abr_index++;
// Setup array of arguments
// TODO: i think arrays of size 0 is an error
int destruct[1];
zval *args[1];
zval **args_ind[1];
int af_index = 0;
destruct[af_index] = 0;
if (by_ref[af_index])
{
if (local_f == NULL)
{
local_f = EG (uninitialized_zval_ptr);
local_f->refcount++;
}
zval **p_arg = &local_f;
// We don’t need to restore ->is_ref afterwards,
// because the called function will reduce the
// refcount of arg on return, and will reset is_ref to
// 0 when refcount drops to 1. If the refcount does
// not drop to 1 when the function returns, but we did
// set is_ref to 1 here, that means that is_ref must
// already have been 1 to start with (since if it had
// not, that means that the variable would have been
// in a copy-on-write set, and would have been
// seperated above).
(*p_arg)->is_ref = 1;
args_ind[af_index] = p_arg;
assert (!in_copy_on_write (*args_ind[af_index]));
args[af_index] = *args_ind[af_index];
}
else
{
zval *arg;
if (local_f == NULL)
arg = EG (uninitialized_zval_ptr);
else
arg = local_f;
args[af_index] = fetch_var_arg (arg, &destruct[af_index]);
if (arg->is_ref)
{
// We dont separate since we don’t own one of ARG’s references.
arg = zvp_clone_ex (arg);
destruct[af_index] = 1;
// It seems we get incorrect refcounts without this.
// TODO This decreases the refcount to zero, which seems wrong,
// but gives the right answer. We should look at how zend does
// this.
arg->refcount--;
}
args[af_index] = arg;
args_ind[af_index] = &args[af_index];
}
af_index++;
phc_setup_error (1, quot;listings_source.phpquot;, 8, NULL TSRMLS_CC);
// save existing parameters, in case of recursion
int param_count_save = printf_fci.param_count;
zval ***params_save = printf_fci.params;
zval **retval_save = printf_fci.retval_ptr_ptr;
zval *rhs = NULL;
// set up params
printf_fci.params = args_ind;
printf_fci.param_count = 1;
printf_fci.retval_ptr_ptr = &rhs;
// call the function
int success = zend_call_function (&printf_fci, &printf_fcic TSRMLS_CC);
assert (success == SUCCESS);
// restore params
printf_fci.params = params_save;
printf_fci.param_count = param_count_save;
printf_fci.retval_ptr_ptr = retval_save;
// unset the errors
phc_setup_error (0, NULL, 0, NULL TSRMLS_CC);
int i;
for (i = 0; i < 1; i++)
{
if (destruct[i])
{
assert (destruct[i]);
zval_ptr_dtor (args_ind[i]);
}
}
// When the Zend engine returns by reference, it allocates a zval into
// retval_ptr_ptr. To return by reference, the callee writes into the
// retval_ptr_ptr, freeing the allocated value as it does. (Note, it may
// not actually return anything). So the zval returned - whether we return
// it, or it is the allocated zval - has a refcount of 1.
// The caller is responsible for cleaning that up (note, this is unaffected
// by whether it is added to some COW set).
// For reasons unknown, the Zend API resets the refcount and is_ref fields
// of the return value after the function returns (unless the callee is
// interpreted). If the function is supposed to return by reference, this
// loses the refcount. This only happens when non-interpreted code is
// called. We work around it, when compiled code is called, by saving the
// refcount into SAVED_REFCOUNT, in the return statement. The downside is
// that we may create an error if our code is called by a callback, and
// returns by reference, and the callback returns by reference. At least
// this is an obscure case.
if (signature->common.return_reference
&& signature->type != ZEND_USER_FUNCTION)
{
assert (rhs != EG (uninitialized_zval_ptr));
rhs->is_ref = 1;
if (saved_refcount != 0)
{
rhs->refcount = saved_refcount;
}
rhs->refcount++;
}
saved_refcount = 0; // for ’obscure cases’
zval_ptr_dtor (&rhs);
Trinity College Dublin 27
if (signature->common.return_reference
&& signature->type != ZEND_USER_FUNCTION)
zval_ptr_dtor (&rhs);
}
28. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Applicability
Everything
Perl
PHP
Ruby
Tcl – I think
Trinity College Dublin 28
29. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Applicability
Everything
Perl
PHP
Ruby
Tcl – I think
Except specification
Lua
Python
Trinity College Dublin 28
30. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Applicability
Everything
Perl
PHP
Ruby
Tcl – I think
Except specification
Lua
Python
Not at all
Javascript
Trinity College Dublin 28
31. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 29
32. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Original Speed-up
0.1x
(10 times slower than the PHP interpreter)
Trinity College Dublin 30
33. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
The problem with copies
<?php
for ($i = 0; $i < $n; $i++)
$str = $str . quot;helloquot;;
?>
<?php
for ($i = 0; $i < $n; $i++)
{
$T = $str . quot;helloquot;;
$str = $T;
}
?>
Trinity College Dublin 31
34. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Optimization
Constant folding
<?php <?php
... ...
$T = quot;5quot; + true; $T = 6;
... ...
?> ?>
Trinity College Dublin 32
35. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Optimization
Constant folding
Constant pooling
<?php
$sum = 0;
for ($i = 0; $i < 10; $i=$i+1)
{
$sum .= quot;helloquot;;
}
?>
Trinity College Dublin 32
36. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Optimization
Constant folding
Constant pooling
Function caching
// printf ($f);
static php_fcall_info printf_info;
{
php_fcall_info_init (quot;printfquot;, &printf_info);
php_hash_find (
LOCAL_ST, quot;fquot;, 5863275, &printf_info.params);
php_call_function (&printf_info);
}
Trinity College Dublin 32
37. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Optimization
Constant folding
Constant pooling
Function caching
Pre-hashing
// $i = 0;
{
zval* p_i;
php_hash_find (LOCAL_ST, quot;iquot;, 5863374, p_i);
php_destruct (p_i);
php_allocate (p_i);
ZVAL_LONG (*p_i, 0);
}
Trinity College Dublin 32
38. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Optimization
Constant folding
Constant pooling
Function caching
Pre-hashing
Symbol-table removal
// $i = 0;
{
php_destruct (local_i);
php_allocate (local_i);
ZVAL_LONG (*local_i, 0);
}
Trinity College Dublin 32
39. Introduction to phc
Challenges to compilation?
Current state of phc
phc solution: use the C API
Next for phc - Analysis and Optimization
Speedup
Experiences with PHP
Current speed-up
3
Speedup of compiled benchmark
2.5
2
1.5
1
0.5
0
ackermann
ary
ary2
ary3
fibo
hash1
hash2
heapsort
mandel
mandel2
matrix
nestedloop
sieve
simple
simplecall
simpleucall
simpleudcall
strcat
mean
Trinity College Dublin 33
40. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 34
41. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 35
42. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Intra-procedural optimizations
Dead-code elimination
Sparse-conditional
constant propagation
Trinity College Dublin 36
43. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Type-inference
<?php
function a ($x, $y)
{
$str = $x . $y;
...
return $str;
}
?>
Trinity College Dublin 37
44. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
User-space handlers
__toString
__get
__set
__isset
__unset
__sleep
__wake
__call
__callStatic
...
Trinity College Dublin 38
45. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
C API handlers
read_property
read_dimension
get
set
cast_object
has_property
unset_property
...
Trinity College Dublin 39
46. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Unknown types propagate
local symbol table
global symbol table
return values
reference parameters
callee parameters
Trinity College Dublin 40
47. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 41
48. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Analysis design
Must model types precisely
(Possibly unnamed) fields, arrays, variables and method
calls
Trinity College Dublin 42
49. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Analysis design
Must model types precisely
(Possibly unnamed) fields, arrays, variables and method
calls
Uses and definitions incomplete
Can’t use def-use chains
Can’t use SSA
Trinity College Dublin 42
50. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Analysis design
Must model types precisely
(Possibly unnamed) fields, arrays, variables and method
calls
Uses and definitions incomplete
Can’t use def-use chains
Can’t use SSA
Imprecise callgraph
Trinity College Dublin 42
51. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Algorithm
Abstract Execution / Interpretation
Trinity College Dublin 43
52. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Algorithm
Abstract Execution / Interpretation
Points-to analysis
*-sensitive
Trinity College Dublin 43
53. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Algorithm
Abstract Execution / Interpretation
Points-to analysis
*-sensitive
Constant-propagation
Precision
Array-indices/field names
Implicit conversions
A. Pioli. Conditional pointer aliasing and constant propagation.
Master’s thesis, SUNY at New Paltz, 1999.
Trinity College Dublin 43
54. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Algorithm
Abstract Execution / Interpretation
Points-to analysis
*-sensitive
Constant-propagation
Precision
Array-indices/field names
Implicit conversions
Type-inference
Virtual calls
Function annotations
Trinity College Dublin 43
55. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Complex cases
Hashtables
Implicit conversions
Variable-variables
$GLOBALS
Static includes
$SESSION
Compiler temporaries
Trinity College Dublin 44
56. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Interesting thoughts
Strip off first loop iteration
Trinity College Dublin 45
57. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Interesting thoughts
Strip off first loop iteration
JITs or Gal/Franz Tracing?
Trinity College Dublin 45
58. Introduction to phc
Current state of phc Simple Optimizations
Next for phc - Analysis and Optimization Advanced Optimizations
Experiences with PHP
Interesting thoughts
Strip off first loop iteration
JITs or Gal/Franz Tracing?
Use string transducer analysis
Sound and Precise Analysis of Web Applications
for Injection Vulnerabilities
Gary Wassermann, Zhendong Su, PLDI’07.
Static approximation of dynamically generated Web pages
Yasuhiko Minamide, WWW 2005
Trinity College Dublin 45
59. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Outline
Introduction to phc
1
Current state of phc
2
Challenges to compilation?
phc solution: use the C API
Speedup
Next for phc - Analysis and Optimization
3
Simple Optimizations
Advanced Optimizations
Experiences with PHP
4
Trinity College Dublin 46
60. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Opinions and conjecture
Opinions and conjecture
Trinity College Dublin 47
61. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Opinions and conjecture
Opinions and conjecture
Language Problems
Trinity College Dublin 47
62. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Opinions and conjecture
Opinions and conjecture
Language Problems
Implementation problems
Trinity College Dublin 47
63. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Opinions and conjecture
Opinions and conjecture
Language Problems
Implementation problems
Community Problems
Trinity College Dublin 47
64. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Opinions and conjecture
Fixes
Remove coupling between libraries and interpreter
Better community interactions:
Pre-commit reviews
Mailing list moderation
Per-area maintainers
Love of the language leads to more tools
Trinity College Dublin 48
65. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Summary
Re-use existing run-time for language
Better yet: standardize libraries (and language?), including
FFI
Analysis needs to be precise, and whole-program
Pessimistic assumptions spread
Language, implementation and community need to be
fixed
All related?
Trinity College Dublin 49
66. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Thanks
phc needs contributors
contribute:
http://phpcompiler.org/contribute.html
mailing list: phc-general@phpcompiler.org
slides: http://www.cs.tcd.ie/~pbiggar/
contact: paul.biggar@gmail.com
Trinity College Dublin 50
67. Introduction to phc
Current state of phc
Next for phc - Analysis and Optimization
Experiences with PHP
Complex cases
Hashtables
Implicit conversions
Variable-variables
$GLOBALS
Static includes
$SESSION
Compiler temporaries
Trinity College Dublin 51