Skip to content

Prefer Single World Query

SuggestionAuto-fixableRoblox
small-rules/prefer-single-world-query

Enforce combining multiple world.get() or world.has() calls into a single call for better Jecs performance.

Rationale

Jecs lets you ask world for multiple components in one get() or has() call. Writing one query per component against the same entity is just leaving performance on the table, and it reads like a shopping list instead of one coherent request.

This rule finds consecutive queries on the same world and entity and collapses them into a single call. It auto-fixes, so you don’t have to hand-merge anything. I’d turn this on anywhere you use Jecs.

Diagnostic Messages

preferSingleGet
Multiple world.get() calls on the same entity should be combined into a single call for better performance. Suggested fix: {{fixedCode}}
preferSingleHas
Multiple world.has() calls on the same entity should be combined into a single call for better performance. Suggested fix: {{fixedCode}}

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/prefer-single-world-query": "error"
}
}

Examples

repeated world get calls
const componentA = world.get(entity, ComponentA);
const componentB = world.get(entity, ComponentB);

After auto-fix

const [componentA, componentB] = world.get(entity, ComponentA, ComponentB);
single world get call
const componentA = world.get(entity, ComponentA);