Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Python performance optimizations with RHEL 9.5

November 21, 2024
Charalampos Stratakis
Related topics:
Artificial intelligenceC, C#, C++LinuxPython
Related products:
Red Hat Enterprise Linux

Share:

    As Python continues playing a central role in diverse fields, such as web development, data science, artificial intelligence and machine learning (AI/ML), performance optimizations in the language are critical to meet the growing demand of modern applications and workloads. In order to meet the growing needs of users and customers, and address bottlenecks across the Red Hat Enterprise Linux (RHEL) ecosystem, Red Hat constantly analyzes data and tests new features in order to provide an enhanced experience while maintaining the same stability guarantees that RHEL is known and trusted for. 

    New performance optimizations in RHEL 9.5 and more

    With the release of RHEL 9.5, Python 3.9 (the default system version Python) and the alternative stacks of Python 3.11 and Python 3.12 were compiled with GCC's -O3 flag. This flag enables a higher optimization level during the compilation, activating more aggressive optimizations aimed at improving performance, such as loop splitting and peeling, predictive commoning, and more at the cost of a potential binary size increase.

    At the same time we have also applied these performance optimizations across Red Hat Enterprise Linux 8.10 Python stacks as well as CentOS Stream 10, where Red Hat Enterprise Linux 10 will be derived from.

    Testing and benchmarking

     As Fedora and Red Hat Enterprise Linux utilize by default GCC’s -O2 flag, we tested the optimizations in Fedora, verifying the performance gains across the interpreter and various third party modules with a minimal binary size increase of 1.16%, and then backported the changes to RHEL. This update brings in line our downstream distributions with Python upstream, which has been using the -O3 optimization flag for some time. Aligning with the upstream approach ensures that Fedora, RHEL and their derivatives are taking full advantage of the performance gains that have been available in the wider Python community.

    Depending on the workload, this change can result in faster performance for both the Python interpreter and applications built on top of it. Python C extensions built using the updated Python interpreters will inherit the -O3 flag and benefit from the change as well.

    In a testing environment, a seemingly basic operation demonstrates the reduced overhead and faster execution times enabled by the new optimizations. A simple loop using the timeit module, which analyzes multiple iterations and applies a consistent warmup. For example: 

    python3.12 -m timeit 'for i in range(1000): j=i'

    However, the true impact of the changes becomes clearer when running more comprehensive benchmarking tools like pyperformance, the Phoronix test suite and the Pytorch benchmarks, which show consistent improvements across a wide range of tests.

    Enhancing AI/ML workloads

    Overall, the adoption of the -O3 flag in Red Hat Enterprise Linux is set to deliver faster Python applications throughout the entire RHEL ecosystem. This will not only enhance the performance of general-purpose Python applications but also provide a significant boost for AI/ML workloads. Python is the dominant language for machine learning and artificial intelligence, with popular frameworks like TensorFlow, Pytorch, and InstructLab being heavily reliant on both Python code and Python C extensions. These workloads, which often rely on heavy computations and large datasets, stand to benefit particularly from the optimizations leading to faster training times, quicker inference and more efficient resource usage. 

    Red Hat’s ongoing commitment to quality, stability, and performance

    As the Python Maintenance team at Red Hat, we continuously test and investigate new features, potential performance improvements as well as resolving bugs and security issues across the Python landscape while collaborating with upstreams to ensure that the latest innovations are available across the ecosystems of Fedora, RHEL and CentOS Stream.

    We encourage Python developers to begin testing their applications with these new optimizations to experience the benefits firsthand. Stay tuned for future updates as we continue to improve the Python stack and optimize performance for a wide range of workloads.

    Related Posts

    • Red Hat Enterprise Linux 9.5: What are the top features for developers?

    • The Hypothesis Testing Library for Python: An Introduction

    • Virtualized database I/O performance improvements in RHEL 9.4

    • Announcing the General Availability of Red Hat Enterprise Linux AI (RHEL AI) Version 1.2!

    • Profiling Python Programs

    Recent Posts

    • Assessing AI for OpenShift operations: Advanced configurations

    • OpenShift Lightspeed: Assessing AI for OpenShift operations

    • OpenShift Data Foundation and HashiCorp Vault securing data

    • Axolotl meets LLM Compressor: Fast, sparse, open

    • What’s new for developers in Red Hat OpenShift 4.19

    What’s up next?

    Learn how large language models (LLMs) are created and use Red Hat Enterprise Linux AI to experiment within an LLM in this hands-on learning path.

    STart the activity
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue