Skip to content

Commit

Permalink
Make some asset loading functions monomorphic (bevyengine#1861)
Browse files Browse the repository at this point in the history
This reduces the size of executables when using bevy as dylib by
ensuring that they get codegened in bevy_assets instead of the game
itself. This by extension avoids pulling in parts of bevy_tasks and
async_task.

Before this change the breakout example was 923k big after this change
it is only 775k big for cg_clif. For cg_llvm in release mode breakout
shrinks from 356k to 316k. For cg_llvm in debug mode breakout shrinks
from 3814k to 3057k.
  • Loading branch information
bjorn3 authored and jihiggins committed Apr 18, 2021
1 parent 1b3db02 commit c9eb2c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@ impl AssetServer {
}

// TODO: properly set failed LoadState in all failure cases
async fn load_async<'a, P: Into<AssetPath<'a>>>(
async fn load_async(
&self,
path: P,
asset_path: AssetPath<'_>,
force: bool,
) -> Result<AssetPathId, AssetServerError> {
let asset_path: AssetPath = path.into();
let asset_loader = self.get_path_asset_loader(asset_path.path())?;
let asset_path_id: AssetPathId = asset_path.get_id();

Expand Down Expand Up @@ -326,16 +325,11 @@ impl AssetServer {
}

pub fn load_untyped<'a, P: Into<AssetPath<'a>>>(&self, path: P) -> HandleUntyped {
let handle_id = self.load_untracked(path, false);
let handle_id = self.load_untracked(path.into(), false);
self.get_handle_untyped(handle_id)
}

pub(crate) fn load_untracked<'a, P: Into<AssetPath<'a>>>(
&self,
path: P,
force: bool,
) -> HandleId {
let asset_path: AssetPath<'a> = path.into();
pub(crate) fn load_untracked(&self, asset_path: AssetPath<'_>, force: bool) -> HandleId {
let server = self.clone();
let owned_path = asset_path.to_owned();
self.server
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/io/file_asset_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn filesystem_watcher_system(asset_server: Res<AssetServer>) {
for path in paths.iter() {
if !changed.contains(path) {
let relative_path = path.strip_prefix(&asset_io.root_path).unwrap();
let _ = asset_server.load_untracked(relative_path, true);
let _ = asset_server.load_untracked(relative_path.into(), true);
}
}
changed.extend(paths);
Expand Down

0 comments on commit c9eb2c1

Please sign in to comment.