Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more GDScript performance optimizations #11518

Merged
merged 4 commits into from
Sep 25, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove several checks on DEBUG_RELEASE
These errors shouldn't be possible on a tested game. Remove the checks
on release. Shaves about 10% off of tight loops.
  • Loading branch information
hpvb committed Sep 25, 2017
commit 0a338a28d913b882f63444820073fecc421cbd5d
17 changes: 13 additions & 4 deletions modules/gdscript/gd_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,35 @@ Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScrip
switch ((p_address & ADDR_TYPE_MASK) >> ADDR_BITS) {

case ADDR_TYPE_SELF: {

#ifdef DEBUG_ENABLED
if (unlikely(!p_instance)) {
r_error = "Cannot access self without instance.";
return NULL;
}
#endif
return &self;
} break;
case ADDR_TYPE_CLASS: {

return &p_script->_static_ref;
} break;
case ADDR_TYPE_MEMBER: {
//member indexing is O(1)
#ifdef DEBUG_ENABLED
if (unlikely(!p_instance)) {
r_error = "Cannot access member without instance.";
return NULL;
}
#endif
//member indexing is O(1)
return &p_instance->members[address];
} break;
case ADDR_TYPE_CLASS_CONSTANT: {

//todo change to index!
GDScript *o = p_script;
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(address, _global_names_count, NULL);
#endif
const StringName *sn = &_global_names_ptr[address];

while (o) {
Expand All @@ -84,18 +89,22 @@ Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScrip
ERR_FAIL_V(NULL);
} break;
case ADDR_TYPE_LOCAL_CONSTANT: {
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(address, _constant_count, NULL);
#endif
return &_constants_ptr[address];
} break;
case ADDR_TYPE_STACK:
case ADDR_TYPE_STACK_VARIABLE: {
#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(address, _stack_size, NULL);
#endif
return &p_stack[address];
} break;
case ADDR_TYPE_GLOBAL: {

#ifdef DEBUG_ENABLED
ERR_FAIL_INDEX_V(address, GDScriptLanguage::get_singleton()->get_global_array_size(), NULL);

#endif
return &GDScriptLanguage::get_singleton()->get_global_array()[address];
} break;
case ADDR_TYPE_NIL: {
Expand Down