Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

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

    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

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    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

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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