Skip to content

Conversation

brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented Jul 25, 2024

This one's a bit weird, since it needs the oparg of the following instruction. This is readily available in tier one, but needs to be smuggled in using an operand in tier two.

Technically, it would be cleaner to just add an additional cache entry to all BINARY_OP instructions and use that here. However, that feels very wasteful for an instruction that already requires quite a bit of special-casing anyways. So instead, just toss the needed value in the operand during projection.

This is mostly for completeness. No impact on perf or stats, although if you squint hard enough you can see very slight increases in trace length and decreases in number of traces and tier one instructions.

@brandtbucher brandtbucher added performance Performance or resource usage skip news interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jul 25, 2024
@brandtbucher brandtbucher self-assigned this Jul 25, 2024
Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've suggested a couple of clarifications, but looks good in general.

*target_local = PyStackRef_FromPyObjectSteal(temp);
_Py_DECREF_SPECIALIZED(right_o, _PyUnicode_ExactDealloc);
ERROR_IF(PyStackRef_IsNull(*target_local), error);
#if TIER_ONE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining how this is handled in tier 2.

// Add cache size for opcode
instr += _PyOpcode_Caches[_PyOpcode_Deopt[opcode]];

if (opcode == BINARY_OP_INPLACE_ADD_UNICODE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this up to the if (uop == _BINARY_OP_INPLACE_ADD_UNICODE) clause above?
I'd like to keep the special casing code in one place.

You'll probably want to add an assert this uop is the last in the expansion, as well. Like we do in if (uop == _PUSH_FRAME) above.

@brandtbucher brandtbucher merged commit d9efa45 into python:main Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants