Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mlua_serialize = ["bevy_mod_scripting_lua?/mlua_serialize"]
mlua_macros = ["bevy_mod_scripting_lua?/mlua_macros"]
mlua_async = ["bevy_mod_scripting_lua?/mlua_async"]


## rhai
rhai = ["bevy_mod_scripting_rhai"]

Expand All @@ -56,8 +57,8 @@ bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", ver
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.0-alpha.7", optional = true }
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
bevy_mod_scripting_functions = { workspace = true }

[workspace.dependencies]
profiling = {version = "1.0" }
bevy = { version = "0.15.0", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.0-alpha.8" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.0-alpha.8", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dashmap = "6"
smallvec = "1.11"
itertools = "0.13"
derivative = "2.2"

profiling = {workspace = true}
[dev-dependencies]
test_utils = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/src/bindings/access_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub struct AccessMap {
individual_accesses: DashMap<u64, AccessCount>,
global_lock: RwLock<AccessCount>,
}

#[profiling::all_functions]
impl AccessMap {
pub fn is_locked_exclusively(&self) -> bool {
let global_lock = self.global_lock.read();
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_mod_scripting_core/src/bindings/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct ReflectAllocator {
allocations: HashMap<ReflectAllocationId, ReflectAllocation>,
types: HashMap<u64, TypeId>,
}

#[profiling::all_functions]
impl ReflectAllocator {
/// Allocates a new [`Reflect`] value and returns an [`AllocationId`] which can be used to access it later.
/// Use [`Self::allocate_boxed`] if you already have an allocated boxed value.
Expand Down Expand Up @@ -206,6 +206,7 @@ impl ReflectAllocator {
}

/// Cleans up dangling script allocations
#[profiling::function]
pub fn garbage_collector(allocator: ResMut<AppReflectAllocator>) {
let mut allocator = allocator.write();
allocator.clean_garbage_allocations()
Expand Down
24 changes: 14 additions & 10 deletions crates/bevy_mod_scripting_core/src/bindings/function/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl FromScript for () {

impl FromScript for bool {
type This<'w> = Self;

#[profiling::function]
fn from_script(
value: ScriptValue,
world: WorldGuard<'_>,
Expand All @@ -67,6 +67,7 @@ macro_rules! impl_from_with_downcast {
$(
impl FromScript for $ty {
type This<'w> = Self;
#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::Integer(i) => Ok(i as $ty),
Expand All @@ -88,6 +89,7 @@ macro_rules! impl_from_stringlike {
$(
impl FromScript for $ty {
type This<'w> = Self;
#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::String(s) => Ok(s.to_string().into()),
Expand All @@ -104,7 +106,7 @@ impl_from_stringlike!(String, PathBuf, OsString);

impl FromScript for char {
type This<'w> = Self;

#[profiling::function]
fn from_script(
value: ScriptValue,
world: WorldGuard<'_>,
Expand All @@ -128,6 +130,7 @@ impl FromScript for char {

impl FromScript for ReflectReference {
type This<'w> = Self;
#[profiling::function]
fn from_script(value: ScriptValue, _world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::Reference(r) => Ok(r),
Expand Down Expand Up @@ -178,6 +181,7 @@ impl<T> From<T> for Val<T> {

impl<T: FromReflect> FromScript for Val<T> {
type This<'w> = Self;
#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::Reference(reflect_reference) => Ok(Val(reflect_reference.with_reflect(
Expand Down Expand Up @@ -221,7 +225,7 @@ impl<T> Deref for Ref<'_, T> {

impl<T: FromReflect> FromScript for Ref<'_, T> {
type This<'a> = Ref<'a, T>;

#[profiling::function]
fn from_script(
value: ScriptValue,
world: WorldGuard<'_>,
Expand Down Expand Up @@ -293,7 +297,7 @@ impl<'a, T> From<&'a mut T> for Mut<'a, T> {

impl<T: FromReflect> FromScript for Mut<'_, T> {
type This<'w> = Mut<'w, T>;

#[profiling::function]
fn from_script(
value: ScriptValue,
world: WorldGuard<'_>,
Expand Down Expand Up @@ -331,7 +335,7 @@ where
for<'w> T::This<'w>: Into<T>,
{
type This<'w> = Self;

#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::Unit => Ok(None),
Expand All @@ -345,7 +349,7 @@ where
for<'w> T::This<'w>: Into<T>,
{
type This<'w> = Self;

#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::List(list) => {
Expand All @@ -368,7 +372,7 @@ where
for<'w> T::This<'w>: Into<T>,
{
type This<'w> = Self;

#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::List(list) if list.len() == N => {
Expand All @@ -390,7 +394,7 @@ where

impl FromScript for DynamicScriptFunctionMut {
type This<'w> = Self;

#[profiling::function]
fn from_script(value: ScriptValue, _: WorldGuard<'_>) -> Result<Self::This<'_>, InteropError>
where
Self: Sized,
Expand All @@ -407,7 +411,7 @@ impl FromScript for DynamicScriptFunctionMut {

impl FromScript for DynamicScriptFunction {
type This<'w> = Self;

#[profiling::function]
fn from_script(value: ScriptValue, _: WorldGuard<'_>) -> Result<Self::This<'_>, InteropError>
where
Self: Sized,
Expand All @@ -428,7 +432,7 @@ where
for<'w> V::This<'w>: Into<V>,
{
type This<'w> = Self;

#[profiling::function]
fn from_script(value: ScriptValue, world: WorldGuard) -> Result<Self, InteropError> {
match value {
ScriptValue::Map(map) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub trait FromScriptRef {
}

impl FromScriptRef for Box<dyn PartialReflect> {
#[profiling::function]
fn from_script_ref(
target: TypeId,
value: ScriptValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ macro_rules! downcast_into_value {
}

impl IntoScriptRef for ReflectReference {
#[profiling::function]
fn into_script_ref(
self_: ReflectReference,
world: WorldGuard,
) -> Result<ScriptValue, InteropError> {
self_.with_reflect(world.clone(), |r| into_script_ref(self_.clone(), r, world))?
}
}

#[profiling::function]
fn into_script_ref(
mut self_: ReflectReference,
r: &dyn PartialReflect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl DynamicScriptFunction {
args: I,
context: FunctionCallContext,
) -> Result<ScriptValue, InteropError> {
profiling::scope!("Dynamic Call ", self.name().clone());
let args = args.into_iter().collect::<VecDeque<_>>();
// should we be inlining call errors into the return value?
let return_val = (self.func)(context, args);
Expand Down Expand Up @@ -151,6 +152,7 @@ impl DynamicScriptFunctionMut {
args: I,
context: FunctionCallContext,
) -> Result<ScriptValue, InteropError> {
profiling::scope!("Dynamic Call Mut", self.name().clone());
let args = args.into_iter().collect::<VecDeque<_>>();
// should we be inlining call errors into the return value?
let mut write = self.func.write();
Expand Down Expand Up @@ -276,7 +278,7 @@ pub struct FunctionKey {
pub struct ScriptFunctionRegistry {
functions: HashMap<FunctionKey, DynamicScriptFunction>,
}

#[profiling::all_functions]
impl ScriptFunctionRegistry {
/// Register a script function with the given name. If the name already exists,
/// the new function will be registered as an overload of the function.
Expand Down Expand Up @@ -525,7 +527,9 @@ macro_rules! impl_script_function {
$( $param::This<'env>: Into<$param>,)*
{
#[allow(unused_mut,unused_variables)]
#[profiling::function]
fn $trait_fn_name(mut self) -> $dynamic_type {

let func = (move |caller_context: FunctionCallContext, mut args: VecDeque<ScriptValue> | {
let res: Result<ScriptValue, InteropError> = (|| {
let received_args_len = args.len();
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub trait DisplayWithWorld: std::fmt::Debug {
self.display_with_world(world)
}
}

#[profiling::all_functions]
impl DisplayWithWorld for ReflectReference {
fn display_with_world(&self, world: WorldGuard) -> String {
ReflectReferencePrinter::new(self.clone()).pretty_print(Some(world))
Expand All @@ -356,7 +356,7 @@ impl DisplayWithWorld for ReflectReference {
ReflectReferencePrinter::new(self.clone()).pretty_print(None)
}
}

#[profiling::all_functions]
impl DisplayWithWorld for ReflectBaseType {
fn display_with_world(&self, world: WorldGuard) -> String {
let mut string = String::new();
Expand All @@ -374,7 +374,7 @@ impl DisplayWithWorld for ReflectBaseType {
string
}
}

#[profiling::all_functions]
impl DisplayWithWorld for ComponentId {
fn display_without_world(&self) -> String {
format!("ComponentOrResource({})", self.index())
Expand All @@ -393,7 +393,7 @@ impl DisplayWithWorld for ComponentId {
}
}
}

#[profiling::all_functions]
impl DisplayWithWorld for ReflectAccessId {
fn display_without_world(&self) -> String {
match self.kind {
Expand Down Expand Up @@ -425,7 +425,7 @@ impl DisplayWithWorld for ReflectAccessId {
}
}
}

#[profiling::all_functions]
impl DisplayWithWorld for TypeId {
fn display_with_world(&self, world: WorldGuard) -> String {
if *self == TypeId::of::<FakeType>() {
Expand Down Expand Up @@ -455,7 +455,7 @@ impl DisplayWithWorld for TypeId {
format!("{:?}", self)
}
}

#[profiling::all_functions]
impl DisplayWithWorld for ScriptValue {
fn display_with_world(&self, world: WorldGuard) -> String {
match self {
Expand Down Expand Up @@ -509,7 +509,7 @@ impl DisplayWithWorld for ScriptValue {
}
}
}

#[profiling::all_functions]
impl<T: DisplayWithWorld> DisplayWithWorld for Vec<T> {
fn display_with_world(&self, world: WorldGuard) -> String {
let mut string = String::new();
Expand Down Expand Up @@ -550,7 +550,7 @@ impl<T: DisplayWithWorld> DisplayWithWorld for Vec<T> {
string
}
}

#[profiling::all_functions]
impl DisplayWithWorld for String {
fn display_with_world(&self, _world: WorldGuard) -> String {
self.to_string()
Expand All @@ -564,7 +564,7 @@ impl DisplayWithWorld for String {
self.to_string()
}
}

#[profiling::all_functions]
impl<K: DisplayWithWorld, V: DisplayWithWorld> DisplayWithWorld
for std::collections::HashMap<K, V>
{
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/src/bindings/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub struct ScriptQueryResult {
// self.try_read().and_then(|world| world.query(query))
// }
// }

#[profiling::all_functions]
impl WorldAccessGuard<'_> {
pub fn query(
&self,
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_mod_scripting_core/src/bindings/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum TypeIdSource {
/// Givent the Tail reference is a container type, use the type id of the keys of the container
Key,
}

#[profiling::all_functions]
impl ReflectReference {
/// Creates a new infinite iterator. This iterator will keep returning the next element reference forever.
pub fn into_iter_infinite(self) -> ReflectRefIter {
Expand Down Expand Up @@ -421,7 +421,7 @@ pub enum ReflectBase {
Resource(ComponentId),
Owned(ReflectAllocationId),
}

#[profiling::all_functions]
impl ReflectBase {
/// Retrieves the pointer to the underlying `dyn PartialReflect` object valid for the 'w lifteime of the world cell
///
Expand Down Expand Up @@ -469,7 +469,7 @@ pub trait ReflectionPathExt {

fn iter(&self) -> impl Iterator<Item = &bevy::reflect::OffsetAccess>;
}

#[profiling::all_functions]
impl ReflectionPathExt for ParsedPath {
/// Assumes the accesses are 1 indexed and converts them to 0 indexed
fn convert_to_0_indexed(&mut self) {
Expand Down Expand Up @@ -505,7 +505,7 @@ pub struct ReflectRefIter {
pub enum IterationKey {
Index(usize),
}

#[profiling::all_functions]
impl ReflectRefIter {
pub fn new_indexed(base: ReflectReference) -> Self {
Self {
Expand Down Expand Up @@ -537,7 +537,7 @@ impl ReflectRefIter {
const fn list_index_access(index: usize) -> bevy::reflect::Access<'static> {
bevy::reflect::Access::ListIndex(index)
}

#[profiling::all_functions]
impl Iterator for ReflectRefIter {
type Item = Result<ReflectReference, InteropError>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl From<HashMap<String, ScriptValue>> for ScriptValue {
ScriptValue::Map(value)
}
}

#[profiling::all_functions]
impl TryFrom<ScriptValue> for ParsedPath {
type Error = InteropError;
fn try_from(value: ScriptValue) -> Result<Self, Self::Error> {
Expand Down
Loading
Loading