Comments (4)
Caching the method bind, builtin method, and utility function pointers with a static
OnceLock
produces the following speedups:
Function | Kind | Uncached | Cached | Percent |
---|---|---|---|---|
Node::get_child_count |
Method Bind | 308ns | 8ns | 2.60% |
Node::is_inside_tree |
Method Bind | 212ns | 5ns | 2.36% |
Node::is_node_ready |
Method Bind | 209ns | 5ns | 2.39% |
minf |
Utility | 94ns | 8ns | 8.51% |
floorf |
Utility | 86ns | 5ns | 5.81% |
StringName::length |
Builtin | 86ns | 7ns | 8.14% |
from gdext.
Manually writing an implementation of StringName::length
where i cache: __method_name
only, __call_fn
only, and both, then running each function 1 million times with black_box in release mode, i get:
Uncached | __method_name |
__call_fn |
both | |
---|---|---|---|---|
Total Average Time | 0.1979221145 | 0.04312633755 | 0.170186928 | 0.01706689335 |
Percent | 100.00% | 21.79% | 85.99% | 8.62% |
Percent Diff | 0.00% | -78.21% | -14.01% | -91.38% |
from gdext.
caching StringName
s in function calls can have a significant improvement. running these functions 1 million times (in a std::hint::black_box(..)
call):
fn generate_string_name() {
let foo = StringName::from("foo");
}
fn cached_string_name() {
static CACHED: OnceLock<StringName> = OnceLock::new();
let foo = CACHED.get_or_init(|| StringName::from("foo"));
}
takes on average 0.15 seconds for the first one and 0.0003 seconds for the second one in release mode.
we do make calls like StringName::from("name")
a lot in our bindings like for method calls and such.
this does require implementing Send
and Sync
for StringName
, but i think that should be safe. StringName
is immutable and i believe thread-safe.
from gdext.
The cached function pointers have been implemented, and with them, StringName
s also no longer need to be instantiated on each call.
For anyone interested in deeper insights, I wrote about it here:
https://godot-rust.github.io/dev/ffi-optimizations-benchmarking
from gdext.
Related Issues (20)
- Trait bound 'Player: GodotDefault' is not satisfied error during Hello World example HOT 3
- `#[func]` function arguments with invalid types produce weird errors HOT 2
- Deep copies taking into account Rust state (unlike `Node::duplicate()`) HOT 8
- Array<Option<Gd<_>>> Crashes on Null Pointer in Godot's Editor HOT 2
- Inheritance and polymorphism proposals
- Virtual function dispatch for Resources not working HOT 4
- Add mocks for some builtin types for use when Godot isn't running HOT 5
- Missing classes in `engine` module relating to navigation HOT 1
- Recent commit causes "GDExtension initialization function 'gdext_rust_init' returned an error" HOT 1
- Vector3 signed_angle_to is incorrect
- Simple VideoStreamPlayback causes thread panic HOT 4
- It is possible to have a `Base` pointing to a dead object HOT 2
- Issues with string & sse4 support HOT 3
- Problems related to multithreaded access imposed by Godot
- It is tricky to figure out how to properly use `WithBaseField` generically
- commit() failing for SurfaceTool in simple case HOT 6
- godot endlessly prompting to restart HOT 5
- Foreign Classes / Interfaces HOT 1
- Converting Typed Arrays to Variant Arrays Panics HOT 12
- Can't export variable with suffix HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gdext.