Daniil Gentili

  • MadelineProto 8.4.18: a major reactive refactoring!

    MadelineProto, the async PHP client API for the telegram MTProto protocol, was updated to 8.4.18!

    This release features a major internal refactoring of the message system and the auth state machine, bringing major stability and performance improvements by removing legacy code and switching to a new reactive model.

    This reactive model avoids some previously problematic state transitions, for example during network issues, by handling the connection state machine using a reactive actor model.

    I’ve created a new reactive programming library based on the actor model, and it will be published as a separate library once it is mature enough!

    Additionally, the docker image is now based on Debian, and features a patched version of PHP with jemalloc for improved performance.

    Fixes:

    • Fix handling of certain network and auth issues
    • Fix some QR code login issues
    • Reduce CPU usage by switching to linked lists instead of zend hashmaps where possible (previously, usage of zend hashmaps forced periodic reallocation to avoid memory leaks caused by frequent removal of keys)
    • Multiple other fixes and improvements
  • Psalm v7: up to 10x performance!

    Announcing the public beta of Psalm v7!

    Psalm is one of the biggest and most powerful PHP Static analysis tools, featuring exclusive features like security analysis, and Psalm v7 brings huge performance improvements to security analysis, up to 10x thanks to a full refactoring of both the internal representation of taints, and optimization of the graph resolution logic.

    A major new feature was also added: combined analysis!

    Combined analysis, enabled by default in Psalm v7, allows running normal analysis, security analysis and dead code analysis all at the same time, within a single run, greatly reducing overall runtimes!

    Future beta releases will also enable taint analysis by default, given that now it can be run alongside normal analysis.

    Psalm v7 also brings performance improvements to dead code analysis, and fixes for list types.

    Even more performance improvements and new features will be released soon!

  • Official Psalm docker image

    Psalm is one of the biggest and most powerful PHP Static analysis tools, featuring exclusive features like security analysis, and in Psalm 6.9, an official, hyperoptimized Docker image was introduced.

    Psalm’s docker image uses a custom build of PHP built from scratch with a custom deepbind patch and the jemalloc allocator, running Psalm +30% faster on average than normal PHP (+50% faster if comparing to PHP without opcache installed).

    My deepbind patch was also merged into PHP and will be available to all users (even those not using the Docker image) in PHP 8.5!

    To use it right now, on PHP 8.4, simply run:

    docker run -v $PWD:/app --rm -it ghcr.io/danog/psalm:latest /composer/vendor/bin/psalm --no-cache

    Issues due to missing extensions can be fixed by enabling them in psalm.xml and/or requiring them in composer.json, see here for more info.

    Extensions not stubbed by Psalm itself (and thus not available as a psalm config option) may be stubbed using traditional PHP stubs.


    This post is part of a series of posts about Psalm v6’s new features, click here to see all the other posts in the series, and subscribe to the newsletter to always stay up to date on the latest Psalm news and developments!


  • Psalm review tool in Psalm 6.3

    Psalm is one of the biggest and most powerful PHP Static analysis tools, featuring exclusive features like security analysis.

    Psalm v6 was recently released, and in Psalm 6.3, a new tool called psalm-review was added.

    It allows users to manually review found issues one by one in your favorite IDE: just start it on a JSON report generated by Psalm, and it will open your preferred IDE on the exact line and column where the issue occurred:

    ./vendor/bin/psalm-review report.json code|phpstorm|code-server [ inv|rev|[~-]IssueType1 ] [ [~-]IssueType2 ] ...

    The tool may also be run using the main `psalm` entry point, useful for example when working with the phar:

    ./vendor/bin/psalm.phar --review report.json code|phpstorm|code-server [ inv|rev|[~-]IssueType1 ] [ [~-]IssueType2 ] ...

    The extra arguments may be used to filter only for issues of the specified types, or for all issues except the specified types (with the ~ or - inversion).

    The rev or inv keywords may be used to start from the end of the report instead of at the beginning.


    This post is part of a series of posts about Psalm v6’s new features, click here to see all the other posts in the series, and subscribe to the newsletter to always stay up to date on the latest Psalm news and developments!

  • Psalm v6 Deep Dive: Copy-on-Write + dynamic task dispatching

    Psalm is one of the biggest and most powerful PHP Static analysis tools, featuring exclusive features like security analysis.

    Psalm v6 was recently released, and soon after in Psalm 6.1, I implemented a major refactoring of multithreaded mode (automatically enabled on Linux/Mac OS) based on amphp/parallel, which greatly improved analysis speeds!

    But why was it so effective? To understand, one must first understand that in the vast majority of PHP multithreaded analysis tools, jobs are distributed statically between threads on startup, which means that towards the end of the analysis, a lot of workers just sit there doing nothing, just waiting for the other workers processing bigger and heavier files to finish.

    However, the new multithreaded mode now allows Psalm to dynamically distribute jobs to workers immediately, as soon as they finish processing their current task, reducing idle worker time and maximizing CPU usage, thus reducing the overall runtime!

    Implementation wasn’t as easy as just plugging in amphp/parallel, because Psalm relies heavily on the copy-on-write semantics of fork(): indeed, Psalm’s multithreaded mode was quite fast even before the refactoring because it doesn’t have to copy all type information to all workers when spawning them, as when workers are spawned using the fork() syscall, the entire memory is not copied to the forked process.

    Instead, it is copied only when a memory page is modified by the forked process, which means that unless workers start modifying large amounts of type information (which usually happens pretty rarely, as most of that data is immutable after Psalm’s scan phase), most of the memory is not copied, leading to large performance improvements.

    amphp/parallel does not support using fork() to spawn workers out of the box, however I managed to add support using a custom context class (taking care to avoid some edge cases around reused file descriptors, which can cause issues with the event loop).

    The maintainer of amphp was kind enough to begin integration of Psalm’s fork context inside of parallel itself after I pinged him, which means amphp users will soon be able to make use of Psalm’s fork context to improve worker spawning performance with copy-on-write fork() semantics.

    This release also adds an additional check to ensure VM overcommitting (the feature which allows copy-on-write optimizations) is enabled in the OS when running Psalm, by ensuring that the vm.overcommit_memory kernel setting is always set to 1.


    This post is the first of a series of technical deep dives into Psalm v6’s performance improvements, which will be released over the next weeks, click here to see all the other posts in the series, and subscribe to the newsletter to always stay up to date on the latest Psalm news and developments!

  • Psalm v6 announcement

    Psalm is one of the biggest and most powerful PHP Static analysis tools, featuring exclusive features like security analysis, and Psalm v6 brings support for PHP 8.4, AMPHP v3, PHP-Parser v5 and much more!

    I am happy to announce that I, Daniil Gentili, am now the main maintainer of Psalm, and thanks to the newly launched Psalm support contracts, I now have the opportunity to work heavily on Psalm, specifically focusing on major performance improvements and improved security analysis.

    This post is the first of a series of technical deep dives into Psalm v6’s performance improvements, which will be released over the next weeks, starting with:

    Psalm v6 Deep Dive: Copy-on-Write + dynamic task dispatching

    To avoid missing the next posts, subscribe to my newsletter to always stay up to date on the latest Psalm news and developments!

    Subscribe to my newsletter to always stay up to date on my projects, and join my community to chat with me!

    Alternatively, you can also join my Telegram channel!

    An RSS feed is also available.

    Among other news, you can now join the new official Psalm news channel and the Psalm community!

    The news channel will be used to share inside exclusive news about upcoming Psalm features (including property hook support, coming within the next few releases!), and the community group can be used to discuss and share the way you use Psalm!


    Do you like Psalm, does your company use it internally to improve security and reliability?

    Consider setting up a support contract: support contracts can cover full integration of Psalm into existing codebases, support for Psalm issues and development of additional Psalm features.

  • Hi

    I’m Daniil Gentili, a senior software artisan: I enjoy working on complex high-performance systems using Rust, Golang, C++, C, PHP, and this is my blog!

    Here I’ll be posting news about all the projects I create and maintain, such as:

    • MadelineProto – An async PHP client API for the telegram MTProto protocol
    • Psalm – A PHP static analysis tool for finding errors and security vulnerabilities in PHP applications
    • php-tokio – Use any async Rust library from PHP!
    • And much more!

    Subscribe to my newsletter to always stay up to date, and join my community to chat with me!

×