GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — gh-129724: gh-156504: Make marshal output independent of reference counts by gpshead · Pull Request #159192 · python/cpython Conversation
|
| default (GIL) | free-threaded | |
|---|---|---|
dumps of the code objects of the stdlib |
3.7% slower | 4.3% slower |
dumps dominated by references (millions of TYPE_REF) |
5-9% slower | |
dumps of unshared data (1M distinct floats) |
32% faster | |
loads of the new output |
3-5% faster |
Writer memory grows by 8 bytes per object with a reference count above 1.
ReferenceTestCase in test_marshal checks exact bytes: single occurrences are not flagged whatever their reference count, interned strings, references at every buffer offset, objects seen before and after the ones they share with, NaNs in sets. test_capi.test_marshal checks that nothing is written on error.
drafted using Claude, reviewed & iterated upon by me.
Fixes #156504
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Documentation build overview
12 files changed ·
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @gpshead for commit 355cb8c 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159192%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The marshal writer decided whether an object can be referenced later (FLAG_REF) from its reference count, so the output for the same value depended on what else in the process held a reference to its parts, and differed between the default and the free-threaded builds' view of the same objects. This is the remaining cause of pythongh-129724 and the cause of pythongh-156504. FLAG_REF is now set exactly on the objects which are written more than once in the dump. The writer still makes one pass: it records the position of the type byte of each object it remembers and of each TYPE_REF, and when the dump is complete it sets the flags and renumbers the references. A reference count of one is only used to skip the hashtable. Interned strings are no longer flagged unconditionally. The reader is unchanged and the format version is not bumped: both the old and the new output are loaded by old and new readers. PyMarshal_WriteObjectToFile() now builds the data in memory and writes it with one fwrite(), since the flags are only known at the end. Nothing is written if the object cannot be marshalled.
355cb8c to
7893950
Compare
|
🤖 New build scheduled with the buildbot fleet by @gpshead for commit 7893950 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159192%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could you reduce the number of NEWS entries to one or two? In What's New, the C API and library changes need to be documented separately because they are in different sections, but I think related changes can be combined into a single NEWS entry. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
ETOOMUCHNEWS - good call, done. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
GH-159290 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ent of reference counts (pythonGH-159192) The marshal writer decided whether an object can be referenced later (FLAG_REF) from its reference count, so the output for the same value depended on what else in the process held a reference to its parts, and differed between the default and the free-threaded builds' view of the same objects. This is the remaining cause of pythongh-129724 and the cause of pythongh-156504. FLAG_REF is now set exactly on the objects which are written more than once in the dump. The writer still makes one pass: it records the position of the type byte of each object it remembers and of each TYPE_REF, and when the dump is complete it sets the flags and renumbers the references. A reference count of one is only used to skip the hashtable. Interned strings are no longer flagged unconditionally. The reader is unchanged and the format version is not bumped: both the old and the new output are loaded by old and new readers. PyMarshal_WriteObjectToFile() now builds the data in memory and writes it with one fwrite(), since the flags are only known at the end. Nothing is written if the object cannot be marshalled. (cherry picked from commit 48f18f0)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Concurrent compilation changes marshal output in free-threaded builds
There was an error while loading. Please reload this page.