• English
  • Čeština
  • Deutsch
  • Español
  • Français
  • Gàidhlig
  • Latviešu
  • Magyar
  • Nederlands
  • Português
  • Português do Brasil
  • Suomi
  • Svenska
  • Türkçe
  • Қазақ
  • বাংলা
  • हिंदी
  • Ελληνικά
  • Log In
  • Communities & Collections
  • Browse OpenUCT
  • English
  • Čeština
  • Deutsch
  • Español
  • Français
  • Gàidhlig
  • Latviešu
  • Magyar
  • Nederlands
  • Português
  • Português do Brasil
  • Suomi
  • Svenska
  • Türkçe
  • Қазақ
  • বাংলা
  • हिंदी
  • Ελληνικά
  • Log In
  1. Home
  2. Browse by Author

Browsing by Author "Spies, Du Toit"

Now showing 1 - 1 of 1
Results Per Page
Sort Options
  • No Thumbnail Available
    Item
    Open Access
    Implementing a prototype HPy backend for Cython: improving Python extension performance
    (2025) Spies, Du Toit; Kuttel, Michelle
    The python programming language has become widely used, including in fields such as scientific computing and artificial intelligence. However, the original and most popular implementation of Python, CPython, is often criticised for its slow performance as compared to other programming languages. Alternate implemen-tations of Python, such as GraalPy, aim to improve the performance of Python coPython programming mpared to CPython, with optimisations such as Just-in-Time compilers and more complex garbage collectors. However, these alternate implementations have worse performance than CPython when using extension modules written in C or C++ using Python's C API, which is closely tied to the CPython implementation. HPy is a proposed alternative to the C API for writing C or C++ extension mod-ules for Python. HPy is implementation-neutral and does not have the same poor performance on non-CPython implementations as the C API. However, Cython, a program that compiles Python code to a C extension module, unfortunately does not yet support HPy. Cython allows users to generate C extensions without using the C API directly, which has made it popular, so HPy support in Cython would have potential benefits, such as automatic generation of HPy extensions. Here we describe the implementation and testing of a prototype HPy backend for Cython, with the aim of improving the performance of extensions generated with Cython on the GraalPy Python implementation. Our HPy backend replaces C API functions, variables, and macros generated by Cython with macros that map to either the C API or HPy. This allows files generated by Cython to compile to either the C API or HPy, while not increasing the amount of code generated. To compare performance, four simple benchmarks testing key aspects of performance were compiled into extension modules with Cython using either our HPy backend or the original C API backend and then run on either CPython or GraalPy. We found that, while HPy can improve extension module performance on GraalPy, HPy modules performed worse on CPython than the C API modules. This is likely due to optimisations in Cython for the C API which are not replicable in HPy, such as directly accessing the memory layout of Python objects. We also identified aspects of HPy that severely impact its performance. Overall, we find that HPy has significant potential advantages over the C API, but requires further improvements to be competitive with the C API on CPython.
UCT Libraries logo

Contact us

Jill Claassen

Manager: Scholarly Communication & Publishing

Email: openuct@uct.ac.za

+27 (0)21 650 1263

  • Open Access @ UCT

    • OpenUCT LibGuide
    • Open Access Policy
    • Open Scholarship at UCT
    • OpenUCT FAQs
  • UCT Publishing Platforms

    • UCT Open Access Journals
    • UCT Open Access Monographs
    • UCT Press Open Access Books
    • Zivahub - Open Data UCT
  • Site Usage

    • Cookie settings
    • Privacy policy
    • End User Agreement
    • Send Feedback

DSpace software copyright © 2002-2026 LYRASIS