{"id":1953,"date":"2024-09-19T22:34:59","date_gmt":"2024-09-19T22:34:59","guid":{"rendered":"https:\/\/www.xome.com\/blog\/?p=1953"},"modified":"2024-11-26T23:13:51","modified_gmt":"2024-11-26T23:13:51","slug":"python-3-11-and-beyond-speeding-up-computations-with-faster-cpython","status":"publish","type":"post","link":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/","title":{"rendered":"Python 3.11 and Beyond: Speeding Up Computations with Faster CPython\u00a0"},"content":{"rendered":"\n<p>Python is widely used in real estate technology when building <a href=\"https:\/\/www.xome.com\/blog\/how-the-machine-learning-lifecycle-helps-improve-avms\/\" target=\"_blank\" rel=\"noreferrer noopener\">machine learning<\/a> models for tasks such as property valuation. At Xome, we use Python to help build our digital solutions that help home buyers and sellers research properties. Even though Python is known to be one of the slower languages compared to C and C++, Python 3.11 and future releases seek to change that.&nbsp;<\/p>\n\n\n\n<p>Python 3.11 came out in 2022 as a part of the Faster CPython effort, which makes Python faster through its optimizations to the interpreter. Because of this, Python 3.11 runs between 10% to 60% faster than 3.10 with an average speed up of 1.25x. An added benefit is that this new release doesn\u2019t require any changes to your code. Instead, Faster CPython optimizes for common code patterns observed.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-faster-cpython\">What is Faster CPython?<\/h2>\n\n\n\n<p>Faster CPython is a project that came about from core developer Mark Shannon\u2019s proposal <a href=\"https:\/\/peps.python.org\/pep-0659\/\" target=\"_blank\" rel=\"noreferrer noopener\">PEP 659<\/a> to make Python five times faster over several releases. Since the four-stage process proposed was too much effort for one person to complete, Microsoft got involved and hired a team of developers along with Mark Shannon and Python\u2019s creator Guido Van Rossum.&nbsp;&nbsp;<\/p>\n\n\n\n<p>There are many improvements in Python 3.11 and Python 3.12 based on this project.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-specializing-adaptive-interpreter-in-python-3-11-nbsp\">Specializing Adaptive Interpreter in Python 3.11&nbsp;<\/h2>\n\n\n\n<p>One notable speed improvement with Python 3.11 is faster code execution. Python code is translated into bytecode and that is the code the interpreter runs. Python 3.11 uses the specializing adaptive interpreter to optimize operations by changing and adapting the bytecode upon execution.&nbsp;<\/p>\n\n\n\n<p><strong>This happens through two steps: quickening and specialization.<\/strong>&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Quickening:<\/strong> The process of choosing candidates for specialization by looking for any bytecode that is executed several times. Any that would benefit from specialization are then replaced by adaptive versions during this step.&nbsp;<\/li>\n\n\n\n<li><strong>Specialization:<\/strong> Bytecode is replaced through a family of specialized instructions.&nbsp;<\/li>\n<\/ul>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Let\u2019s look at an example of the bytecode instructions using the <strong>dis <\/strong>package. The <strong>dis <\/strong>package can help analyze bytecode by disassembling it.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"510\" height=\"208\" src=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python1.png\" alt=\"\" class=\"wp-image-1962\" srcset=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python1.png 510w, https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python1-300x122.png 300w\" sizes=\"(max-width: 510px) 100vw, 510px\" \/><\/figure>\n\n\n\n<p>The output of the bytecode instructions should look like this:&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"516\" height=\"234\" src=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python2.png\" alt=\"\" class=\"wp-image-1963\" srcset=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python2.png 516w, https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python2-300x136.png 300w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/figure>\n\n\n\n<p>When running code where we are adding 5 and 7, 8 times, the output of the bytecode instructions changes.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"514\" height=\"174\" src=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python3.png\" alt=\"\" class=\"wp-image-1965\" srcset=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python3.png 514w, https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python3-300x102.png 300w\" sizes=\"(max-width: 514px) 100vw, 514px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"516\" height=\"236\" src=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python4.png\" alt=\"\" class=\"wp-image-1966\" srcset=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python4.png 516w, https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/python4-300x137.png 300w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/figure>\n\n\n\n<p>The bytecode <strong>BINARY_OP<\/strong> is now replaced by <strong>BINARY_OP_ADD_INT<\/strong>. The Python interpreter detected that there were multiple calls done repeatedly with two integers, and then specialized the bytecode based on that detection. The specialized bytecode is what will run in the future.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faster-startup-times-nbsp\">Faster Startup Times&nbsp;<\/h2>\n\n\n\n<p>When the Python interpreter initializes upon an executed script, it can cost programs a few milliseconds before it runs. That startup time can significantly affect your program\u2019s performance.&nbsp;<\/p>\n\n\n\n<p>Overhead happens when Python imports modules, and you can use the -X importtime option to see the time spent importing different modules. You will see from these numbers that<s>&nbsp;<\/s> imports are happening faster with Python 3.11. This is because it no longer stores bytecode in the <strong>__<\/strong><strong>pycache<\/strong><strong>__<\/strong><strong> <\/strong>directory. Modules for startup are frozen, and Code Objects and bytecode are statically allocated by the interpreter, reducing the steps in execution making it quicker to load them into memory.&nbsp;&nbsp;<\/p>\n\n\n\n<p>As a result, the interpreter startup time is now 10-15% faster in Python 3.11 with the biggest impact for short-running programs.&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-changes-in-python-3-12\">Changes in Python 3.12<\/h2>\n\n\n\n<p>Python 3.11 and 3.12 mark a significant milestone in speeding up computations in Python. As Python continues to evolve, it becomes increasingly powerful, making it an attractive choice for building digital property solutions. You can keep up with the Faster CPython project progress on <a href=\"https:\/\/github.com\/faster-cpython\/ideas\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>.&nbsp;&nbsp;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discover how Python 3.11&#8217;s Faster CPython effort is making Python faster for real estate technology and machine learning tasks.<\/p>\n","protected":false},"author":2,"featured_media":1956,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107],"tags":[161,160,118],"class_list":["post-1953","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-real-estate-tech","tag-tech-development","tag-tech-innovation","tag-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.3 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Faster CPython: Boosting Python Performance for Real Estate - Xome | Blog<\/title>\n<meta name=\"description\" content=\"Discover how Python 3.11&#039;s Faster CPython effort is making Python faster for real estate technology and machine learning tasks.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python 3.11 and Beyond: Speeding Up Computations with Faster CPython\u00a0\" \/>\n<meta property=\"og:description\" content=\"Discover how Python 3.11&#039;s Faster CPython effort is making Python faster for real estate technology and machine learning tasks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/\" \/>\n<meta property=\"og:site_name\" content=\"Xome | Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/XomeRealEstate\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-19T22:34:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-26T23:13:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/altumcode-dC6Pb2JdAqs-unsplash-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1801\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Xome\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@XomeRealEstate\" \/>\n<meta name=\"twitter:site\" content=\"@XomeRealEstate\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Xome\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Faster CPython: Boosting Python Performance for Real Estate - Xome | Blog","description":"Discover how Python 3.11's Faster CPython effort is making Python faster for real estate technology and machine learning tasks.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/","og_locale":"en_US","og_type":"article","og_title":"Python 3.11 and Beyond: Speeding Up Computations with Faster CPython\u00a0","og_description":"Discover how Python 3.11's Faster CPython effort is making Python faster for real estate technology and machine learning tasks.","og_url":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/","og_site_name":"Xome | Blog","article_publisher":"https:\/\/www.facebook.com\/XomeRealEstate","article_published_time":"2024-09-19T22:34:59+00:00","article_modified_time":"2024-11-26T23:13:51+00:00","og_image":[{"width":2560,"height":1801,"url":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/altumcode-dC6Pb2JdAqs-unsplash-scaled.jpg","type":"image\/jpeg"}],"author":"Xome","twitter_card":"summary_large_image","twitter_creator":"@XomeRealEstate","twitter_site":"@XomeRealEstate","twitter_misc":{"Written by":"Xome","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#article","isPartOf":{"@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/"},"author":{"name":"Xome","@id":"https:\/\/www.xome.com\/blog\/#\/schema\/person\/9ba9f5a5815a35c244a30044cd1fb392"},"headline":"Python 3.11 and Beyond: Speeding Up Computations with Faster CPython\u00a0","datePublished":"2024-09-19T22:34:59+00:00","dateModified":"2024-11-26T23:13:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/"},"wordCount":599,"publisher":{"@id":"https:\/\/www.xome.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#primaryimage"},"thumbnailUrl":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/altumcode-dC6Pb2JdAqs-unsplash-scaled.jpg","keywords":["tech development","tech innovation","technology"],"articleSection":["Real Estate Tech"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/","url":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/","name":"Faster CPython: Boosting Python Performance for Real Estate - Xome | Blog","isPartOf":{"@id":"https:\/\/www.xome.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#primaryimage"},"image":{"@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#primaryimage"},"thumbnailUrl":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/altumcode-dC6Pb2JdAqs-unsplash-scaled.jpg","datePublished":"2024-09-19T22:34:59+00:00","dateModified":"2024-11-26T23:13:51+00:00","description":"Discover how Python 3.11's Faster CPython effort is making Python faster for real estate technology and machine learning tasks.","breadcrumb":{"@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#primaryimage","url":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/altumcode-dC6Pb2JdAqs-unsplash-scaled.jpg","contentUrl":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2024\/09\/altumcode-dC6Pb2JdAqs-unsplash-scaled.jpg","width":2560,"height":1801,"caption":"Code on a Macbook screen sitting on a desk next to a pencil cup"},{"@type":"BreadcrumbList","@id":"https:\/\/www.xome.com\/blog\/python-3-11-and-beyond-speeding-up-computations-with-faster-cpython\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.xome.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Real Estate Tech","item":"https:\/\/www.xome.com\/blog\/category\/real-estate-tech\/"},{"@type":"ListItem","position":3,"name":"Python 3.11 and Beyond: Speeding Up Computations with Faster CPython\u00a0"}]},{"@type":"WebSite","@id":"https:\/\/www.xome.com\/blog\/#website","url":"https:\/\/www.xome.com\/blog\/","name":"Xome | Blog","description":"","publisher":{"@id":"https:\/\/www.xome.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.xome.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.xome.com\/blog\/#organization","name":"Xome | Blog","url":"https:\/\/www.xome.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.xome.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2022\/10\/xome-logo-blaze.svg","contentUrl":"https:\/\/www.xome.com\/blog\/wp-content\/uploads\/2022\/10\/xome-logo-blaze.svg","width":64,"height":30,"caption":"Xome | Blog"},"image":{"@id":"https:\/\/www.xome.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/XomeRealEstate","https:\/\/x.com\/XomeRealEstate","https:\/\/www.instagram.com\/xome_com","https:\/\/www.linkedin.com\/company\/xome"]},{"@type":"Person","@id":"https:\/\/www.xome.com\/blog\/#\/schema\/person\/9ba9f5a5815a35c244a30044cd1fb392","name":"Xome","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6a23391c131d2bcbe1b80b2697e5f17546685a7b6e8f4f12dc0324ab4d535802?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6a23391c131d2bcbe1b80b2697e5f17546685a7b6e8f4f12dc0324ab4d535802?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6a23391c131d2bcbe1b80b2697e5f17546685a7b6e8f4f12dc0324ab4d535802?s=96&d=mm&r=g","caption":"Xome"},"url":"https:\/\/www.xome.com\/blog\/author\/jfritsche\/"}]}},"_links":{"self":[{"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/posts\/1953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/comments?post=1953"}],"version-history":[{"count":5,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/posts\/1953\/revisions"}],"predecessor-version":[{"id":1967,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/posts\/1953\/revisions\/1967"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/media\/1956"}],"wp:attachment":[{"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/media?parent=1953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/categories?post=1953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xome.com\/blog\/wp-json\/wp\/v2\/tags?post=1953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}