Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dataflow analysis in the compiler to avoid runtime NULL checks #93143

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
@sweeneyde

Description

@sweeneyde

LOAD_FAST accounts for14.6% of all bytecodes executed. Including superinstructions brings this up to 14.6+4.7+4.6+2.4+0.9 = 27.1%

cpython/Python/ceval.c

Lines 1864 to 1872 in202ed25

TARGET(LOAD_FAST) {
PyObject*value=GETLOCAL(oparg);
if (value==NULL) {
gotounbound_local_error;
}
Py_INCREF(value);
PUSH(value);
DISPATCH();
}

We can turn this NULL-check into an assertion in many cases, where we can determine at compile time that the local variable is already initialized. Preliminary tests show that almost allLOAD_FAST instructions can be statically analyzed to be loading already-initialized variables.

The one twist is handlingdel frame.f_locals["x"] orframe.f_lineno = 17, where previously-safe loads could become unsafe. For now, we can just replace all theLOAD_FAST (no null check) withLOAD_FAST_CHECK in that particular code object.

See alsofaster-cpython/ideas#306

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp