Skip to content

[Refactor]: Hoist _node_name evaluation out of the inner loop in get_entity_context #806

Description

@suhaniiz

Is your feature request related to a problem? Please describe.

Yes, I'm frustrated by redundant CPU operations running inside tight loops. Inside get_entity_context, the variable assignment left = _node_name(graph, node_id) is currently located deep inside the for neighbor_id in neighbors: loop block. Because the node_id value stays completely constant for the entire duration of its neighbors' loop execution, evaluating its string name over and over is entirely redundant. If a node has 50 neighbors, the string retrieval functions execute 50 times instead of once.

Describe the solution you'd like

I want to hoist the statement left = _node_name(graph, node_id) up by exactly one block level. It should sit directly underneath the outer for node_id in matched_nodes: block but above the inner neighbor iteration loop. This will cache the string value once per matched node, saving significant CPU cycles when handling dense, highly-connected query graphs.

Describe alternatives you've considered

No response

Additional Context

No response

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to build this.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or improvementgssocGirlScript Summer of Code 2026 issue/PR

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions