Skip to content

Instantly share code, notes, and snippets.

View sergey-miryanov's full-sized avatar
💭
Father of the little toddler, may be spontaneously unavailable

Sergey Miryanov sergey-miryanov

💭
Father of the little toddler, may be spontaneously unavailable
View GitHub Profile
@sergey-miryanov
sergey-miryanov / run_sphinx_bench.py
Created December 4, 2025 20:50 — forked from nascheme/run_sphinx_bench.py
Benchmark of sphinx processing typing.rst file
#!/usr/bin/env ./python
import contextlib
import os
import sys
import shutil
import subprocess
import time
import venv
from pathlib import Path
import tempfile
@sergey-miryanov
sergey-miryanov / gc_big.py
Created December 4, 2025 20:49 — forked from nascheme/gc_big.py
Python GC benchmark based on OCaml pre-fetch PR
import gc
import time
import statistics
# Adapted from https://gist.github.com/stedolan/4369a0fa27820e27d6e56bee5e412896
# See https://github.com/ocaml/ocaml/pull/10195
#
# In Python (free threading), this uses closer to 1.9 GiB of memory isntead of 800 MiB
# perf stat -e L1-dcache-loads,L1-dcache-load-misses,LLC-loads,LLC-load-misses ./python gc_big_800m.py
@sergey-miryanov
sergey-miryanov / gc_big_tree.py
Created December 4, 2025 20:49 — forked from nascheme/gc_big_tree.py
BTree benchmark for testing cyclic GC performance
import sys
import gc
import random
import time
import collections.abc
import statistics
# perf stat -e L1-dcache-loads,L1-dcache-load-misses,LLC-loads,LLC-load-misses ./python gc_big_tree.py
# perf stat -e l3_request_g1.caching_l3_cache_accesses,l3_comb_clstr_state.request_miss ./python gc_big_tree.py

asyncio

async generator's finalization is broken

import asyncio
work_done = False

async def cursor():
 try:
+--------------------------+----------+------------------------+
| Benchmark | win-main | main |
+==========================+==========+========================+
| 2to3 | 342 ms | 171 ms: 2.01x faster |
+--------------------------+----------+------------------------+
| async_generators | 436 ms | 269 ms: 1.62x faster |
+--------------------------+----------+------------------------+
| asyncio_tcp | 659 ms | 301 ms: 2.19x faster |
+--------------------------+----------+------------------------+
| asyncio_tcp_ssl | 1.82 sec | 801 ms: 2.27x faster |
+--------------------------+----------+------------------------+
| Benchmark | win-main | main |
+==========================+==========+========================+
| 2to3 | 342 ms | 174 ms: 1.97x faster |
+--------------------------+----------+------------------------+
| async_generators | 436 ms | 262 ms: 1.66x faster |
+--------------------------+----------+------------------------+
| asyncio_tcp | 659 ms | 304 ms: 2.17x faster |
+--------------------------+----------+------------------------+
| asyncio_tcp_ssl | 1.82 sec | 805 ms: 2.26x faster |
## Бессмертные объекты и субинтерпретаторы
Интересный факт - если посмотреть код реализации субинтерпретаторов, то никаких отсылок к бессмертным объектам найти не удастся. При этом они являются неотъемлемой основой субинтерпретаторов в CPython.
Как это происходит?
Как уже упоминалось выше, к бессмертным объектам относятся:
1. *статически* выделенные константы - `None`, `False`, `True`, `...`, `NotImplementedType`, `0`, `1`, `''`, `b''`, `()`. (`object.c:_Py_GetConstant_Init`)
2. целые числа в диапазоне [-5, 256] (`pycore_runtime_structs.h:_Py_static_objects`)
3. символы в кодировке latin1
4. статические типы (`_Py_TPFLAGS_STATIC_BUILTIN`), а также их компоненты, такие как, базовый класс, список базовых классов, `MRO` (method-resolution order)
5. интернированные строки и идентификаторы (`pycore_runtime_structs.h:_Py_cached_objects`)
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"newline": true,
"segments": [
{
"type": "text",
"style": "plain",
def func():
raise ConnectionError
# 1 вариант - обрабатывает и подавляет исключение
try:
func()
except ConnectionError as exc:
print('exception: ', type(exc), exc)
# получите сообщение:
# exception: <class 'ConnectionError'>
using Serilog;
using Serilog.Core;
using Serilog.Events;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console(formatProvider:new GuidFormatter())
.Destructure.With<GuidDestructuringPolicy>()
.Destructure.ByTransforming<CustomClass>(Helper.ToString)
.Destructure.ByTransforming<CustomStruct>(Helper.ToString)
.CreateLogger();