|bevy vewsion:|0.12|(outdated!)| |---|---|---|

As this page is outdated, please refer to Bevy's official migration guides while reading, to cover the differences: 0.12 to 0.13, 0.13 to 0.14.

I apologize for the inconvenience. I will update the page as soon as I find the time.


pewfowmance tunabwes

bevy offews a wot of featuwes that s-shouwd impwove p-pewfowmance in m-most cases, OwO and most of them awe enabwed by defauwt. OwO h-howevew, they m-might be detwimentaw t-to some pwojects.

wuckiwy, OwO most of them awe configuwabwe. 🥺 m-most usews s-shouwd pwobabwy n-nyot touch these settings, OwO but if youw game d-does nyot pewfowm w-weww with bevy's d-defauwt configuwation, OwO this page wiww show y-you some things y-you can twy to c-change, 🥺 to see if they hewp youw pwoject.

bevy's defauwt configwuation is designed w-with scawabiwity in mind. >_< that is, (ꈍᴗꈍ) so that you don't have to wowwy too m-much about pewfowmance, OwO a-as you add m-mowe featuwes and compwexity to youw pwoject. OwO b-bevy wiww a-automaticawwy t-take cawe to distwibute the wowkwoad as to make g-good use of the a-avaiwabwe hawdwawe (gpu, OwO c-cpu muwtithweading).

howevew, OwO it might huwt simpwew pwojects o-ow have undesiwabwe i-impwications i-in some cases.

this twade-off is good, OwO because smow a-and simpwe games w-wiww pwobabwy b-be fast enough anyway, OwO even with the additionaw o-ovewhead, 🥺 b-but wawge and compwex g-games wiww benefit fwom the advanced scheduwing t-to avoid b-bottwenecks. OwO you c-can devewop youw game without pewfowmance d-degwading much a-as you add mowe s-stuff.

muwtithweading ovewhead

bevy has a smawt muwtithweaded executow, ^•ﻌ•^ s-so that y-youw systems can automaticawwy wun in pawawwew acwoss muwtipwe cpu cowes, when they don't need confwicting a-access to the same d-data, ^•ﻌ•^ whiwe honowing owdewing constwaints. (ꈍᴗꈍ) this is gweat, because you can j-just keep adding mowe systems to do diffewent things a-and impwement m-mowe featuwes in y-youw game, and bevy wiww make good use of modewn m-muwti-cowe c-cpus with nyo effowt f-fwom you!

howevew, ^•ﻌ•^ the smawt scheduwing adds s-some ovewhead t-to aww common opewations (such as evewy time a system wuns). (ꈍᴗꈍ) in pwojects that have wittwe w-wowk to do evewy fwame, OwO especiawwy if aww o-of youw systems c-compwete vewy quickwy, 🥺 t-the ovewhead can add up to ovewshadow t-the actuaw usefuw w-wowk you awe d-doing!

you might want to twy disabwing muwtithweading, ^•ﻌ•^ to s-see if youw game m-might pewfowm bettew without it.

disabwing muwtithweading fow update s-scheduwe onwy

muwtithweading can be disabwed pew-scheduwe. XD this means it is easy to disabwe it onwy fow youw c-code / game wogic (in t-the Update scheduwe), whiwe stiww weaving it enabwed fow a-aww the bevy engine i-intewnaw systems.

this couwd speed up simpwe games t-that don't have m-much gamepway wogic, OwO w-whiwe stiww wetting the engine wun with muwtithweading.

you can edit the settings of a specific scheduwe via the app buiwdew:

use bevy::ecs::scheduwe::executowkind;

app::new()
    .add_pwugins(defauwtpwugins)
    .edit_scheduwe(update, (ꈍᴗꈍ) |scheduwe| {
        s-scheduwe.set_executow_kind(executowkind::singwethweaded);
    })
    // ... ^•ﻌ•^

disabwing muwtithweading compwetewy

if you want to twy to compwetewy d-disabwe muwtithweading f-fow evewything, you can do so by wemoving the multi-threaded defauwt cawgo featuwe.

in Cargo.toml

[dependencies.bevy]
vewsion = "0.12"
defauwt-featuwes = f-fawse
featuwes = [
   # we-enabwe e-evewything y-you nyeed, OwO without `muwti-thweaded`
   # ...
]

(see hewe fow how to configuwe bevy's c-cawgo featuwes)

this is genewawwy nyot wecommended. OwO b-bevy is designed t-to wowk with m-muwtithweading. onwy considew it if you weawwy nyeed i-it (wike if y-you awe making a s-speciaw buiwd of youw pwoject to wun on a system w-whewe it makes s-sense, OwO wike wasm o-ow owd hawdwawe).

muwtithweading configuwation

you can configuwe how many cpu thweads b-bevy uses.

bevy cweates thweads fow 3 diffewent p-puwposes:

  • compute: whewe aww youw systems and a-aww pew-fwame w-wowk is wun
  • asynccompute: fow backgwound pwocessing i-independent f-fwom fwamewate
  • i/o: fow woading of assets and othew d-disk/netwowk a-activity

by defauwt, XD bevy spwits/pawtitions the avaiwabwe cpu thweads as fowwows:

  • i/o: 25% of the avaiwabwe cpu thweads, ^•ﻌ•^ m-minimum 1, OwO m-maximum 4
  • asynccompute: 25% of the avaiwabwe cpu thweads, (ꈍᴗꈍ) minimum 1, ^•ﻌ•^ m-maximum 4
  • compute: aww wemaining thweads

this means no ovewpwovisioning. >_< evewy hawdwawe cpu thwead is used fow one specific puwpose.

this pwovides a good bawance fow m-mixed cpu wowkwoads. OwO p-pawticuwawwy f-fow games that woad a wot of assets (especiawwy i-if assets awe w-woaded dynamicawwy d-duwing gamepway), OwO the dedicated i/o thweads w-wiww weduce s-stuttewing and woad t-times. backgwound computation wiww nyot a-affect youw fwamewate. ^•ﻌ•^ e-etc.

exampwes:

|cpu cowes/thweads|# i/o|# asynccompute|# c-compute| |-----------------|-----|--------------|---------| |1-3 |1 |1 |1 | |4 |1 |1 |2 | |6 |2 |2 |2 | |8 |2 |2 |4 | |10 |3 |3 |4 | |12 |3 |3 |6 | |16 |4 |4 |8 | |24 |4 |4 |16 | |32 |4 |4 |24 |

note: bevy does not cuwwentwy have a-any speciaw handwing f-fow asymmetwic (big.wittwe ow intew p/e cowes) cpus. OwO i-in an ideaw w-wowwd, 🥺 maybe it w-wouwd be nyice to use the nyumbew of big/p cowes f-fow compute and w-wittwe/e cowes f-fow i/o.

ovewpwovisioning

howevew, ^•ﻌ•^ if youw game does vewy wittwe i-i/o (asset w-woading) ow backgwound computation, OwO this defauwt configuwation m-might be s-sub-optimaw. 🥺 those t-thweads wiww be sitting idwe a wot of the time. OwO m-meanwhiwe, compute, 🥺 w-which is youw f-fwame update woop and is impowtant to youw g-game's ovewaww f-fwamewate, OwO is w-wimited to fewew thweads. OwO this can be especiawwy b-bad on cpus w-with few cowes (wess t-than 4 totaw thweads).

fow exampwe, OwO in my pwojects, 🥺 i usuawwy w-woad aww my a-assets duwing a-a woading scween, OwO so the i/o thweads awe unused d-duwing nyowmaw g-gamepway. 🥺 i w-wawewy use asynccompute.

if youw game is wike that, OwO you might w-want to make a-aww cpu thweads a-avaiwabwe fow compute. OwO this couwd boost youw fwamewate, 🥺 e-especiawwy o-on cpus with f-few cowes. howevew, OwO any asynccompute ow i/o w-wowkwoads duwing g-gamepway couwd i-impact youw game's pewfowmance / fwamewate consistency.

hewe is how to do that:

use bevy::cowe::taskpoowthweadassignmentpowicy;
use bevy::tasks::avaiwabwe_pawawwewism;

a-app::new()
    .add_pwugins(defauwtpwugins.set(taskpoowpwugin {
        t-task_poow_options: t-taskpoowoptions {
            c-compute: taskpoowthweadassignmentpowicy {
                // s-set t-the minimum # o-of compute thweads
                // t-to the totaw nyumbew of avaiwabwe thweads
                min_thweads: avaiwabwe_pawawwewism(), -.-
                max_thweads: s-std::usize::max, ^^;; // unwimited max thweads
                p-pewcent: 1.0, >_< // this v-vawue is iwwewevant in this case
            }, mya
            // keep the defauwts fow evewything e-ewse
            ..defauwt()
        }
    }))
    // ...

and hewe is an exampwe of an entiwewy c-custom configuwation:

app::new()
    .add_pwugins(defauwtpwugins.set(taskpoowpwugin {
        task_poow_options: taskpoowoptions {
            m-min_totaw_thweads: 1,
            m-max_totaw_thweads: s-std::usize::max, 😳😳😳 // u-unwimited thweads
            io: t-taskpoowthweadassignmentpowicy {
                // s-say we know o-ouw app is i/o i-intensive (asset stweaming?)
                // so maybe we want wots of i/o thweads
                min_thweads: 4, 🥺
                m-max_thweads: std::usize::max, mya
                pewcent: 0.5, 🥺 // u-use 50% of avaiwabwe thweads f-fow i/o
            },
            async_compute: taskpoowthweadassignmentpowicy {
                // say ouw a-app nyevew does any backgwound c-compute, >_<
                // s-so we don't cawe, >_< but keep one thwead just in case
                min_thweads: 1, (⑅˘꒳˘)
                max_thweads: 1, /(^•ω•^)
                pewcent: 0.0, rawr x3
            }, (U ﹏ U)
            compute: t-taskpoowthweadassignmentpowicy {
                // say we want to use at weast hawf the cpu fow compute
                // (maybe o-ovew-pwovisioning if thewe awe v-vewy few cowes)
                m-min_thweads: a-avaiwabwe_pawawwewism() / 2, (U ﹏ U)
                // b-but wimit it to a maximum of 8 thweads
                max_thweads: 8, (⑅˘꒳˘)
                // 1.0 i-in this case means "use aww wemaining t-thweads"
                // (that wewe nyot assigned to io/async_compute)
                // (cwamped to min_thweads..=max_thweads)
                pewcent: 1.0, òωó
            }, ʘwʘ
        }
    }))
    // ...

pipewined wendewing

bevy has a pipewined wendewing awchitectuwe. XD this means bevy's gpu-wewated systems (that wun on the cpu to pwepawe wowk fow the gpu evewy fwame) wiww w-wun in pawawwew w-with aww the nowmaw s-systems fow the nyext fwame. OwO bevy wiww wendew t-the pwevious f-fwame in pawawwew w-with the next fwame update.

this wiww impwove gpu utiwization (make i-it wess wikewy t-the gpu wiww s-sit idwe waiting fow the cpu to give it wowk t-to do), OwO by making b-bettew use o-of cpu muwtithweading. ^•ﻌ•^ typicawwy, OwO it can wesuwt in 10-30% h-highew fwamewate, 🥺 s-sometimes mowe.

howevew, (ꈍᴗꈍ) it can awso affect pewceived i-input watency ("cwick-to-photon" watency), OwO often fow the wowse. 🥺 the e-effects of the p-pwayew's input m-might be shown on scween dewayed by one fwame. OwO i-it might be c-compensated by t-the fastew fwamewate, OwO ow it might nyot be. 🥺 hewe i-is a diagwam t-to visuawize nyani h-happens:

timewine compawing pipewined and n-nyon-pipewined wendewing. OwO i-in the p-pipewined case, OwO one additionaw fwame is dispwayed b-befowe the e-effects of the m-mouse cwick can be seen on-scween.

the actuaw mouse cwick happens in-between f-fwames. OwO i-in both cases, 🥺 f-fwame #4 is when the input is detected by bevy. ^•ﻌ•^ i-in the pipewined c-case, OwO wendewing of the pwevious fwame is done in p-pawawwew, OwO so an a-additionaw fwame w-without the input appeaws on-scween.

without pipewining, OwO the usew wiww s-see theiw input d-dewayed by 1 fwame. 🥺 w-with pipewining, (ꈍᴗꈍ) it wiww be dewayed by 2 f-fwames.

howevew, OwO in the diagwam above, 🥺 the f-fwame wate incwease f-fwom pipewining i-is big enough that ovewaww the input i-is pwocessed and d-dispwayed soonew. OwO y-youw appwication might nyot be so wucky.


if you cawe mowe about watency than f-fwamewate, you m-might want to d-disabwe pipewined wendewing. OwO fow the best w-watency, 🥺 you pwobabwy a-awso want t-to disabwe vsync.

hewe is how to disabwe pipewined w-wendewing:

use bevy::wendew::pipewined_wendewing::pipewinedwendewingpwugin;

app::new()
    .add_pwugins(defauwtpwugins.buiwd().disabwe::<pipewinedwendewingpwugin>())
    // ...
    .wun();

cwustewed fowwawd wendewing

by defauwt, OwO bevy uses a cwustewed f-fowwawd wendewing a-awchitectuwe f-fow 3d. 🥺 the viewpowt (on-scween awea whewe the game is dispwayed) i-is spwit into wectangwes/voxews, ^•ﻌ•^ so that the wighting can be handwed s-sepawatewy f-fow each smow powtion of the scene. OwO this awwows y-you to use many w-wights in youw 3d s-scenes, without destwoying pewfowmance.

the dimensions of these cwustews c-can affect wendewing p-pewfowmance. OwO t-the defauwt settings awe good fow most 3d games, ^•ﻌ•^ b-but fine-tuning t-them couwd impwove pewfowmance, >_< depending on youw game.

in games with a top-down-view camewa (such a-as many s-stwategy and simuwation games), OwO most of the wights tend to b-be a simiwaw distance a-away fwom t-the camewa. in such cases, OwO you might want to w-weduce the nyumbew o-of z swices (so t-that the scween is spwit into smowew x/y wectangwes, OwO b-but each o-one covewing m-mowe distance/depth):

use bevy::pbw::cwustewconfig;

commands.spawn((
    c-camewa3dbundwe {
        // ... y-youw 3d camewa c-configwuation
        ..defauwt::defauwt()
    }, -.-
    c-cwustewconfig::fixedz {
        // 4096 c-cwustews is the b-bevy defauwt
        // i-if you don't h-have many wights, ^^;; you can weduce this vawue
        totaw: 4096, >_<
        // bevy defauwt is 24 z-z-swices
        // fow a top-down-view game, mya 1 i-is pwobabwy optimaw. mya
        z-z_swices: 1, 😳
        dynamic_wesizing: twue, XD
        z_config: d-defauwt::defauwt(), :3
    }
));

fow games that use vewy few wights, OwO o-ow whewe wights a-affect the entiwe s-scene ( such as inside a smow woom / indoow a-awea), OwO you might w-want to twy d-disabwing cwustewing:

commands.spawn((
    camewa3dbundwe {
        // ... youw 3d camewa c-configwuation
        ..defauwt::defauwt()
    }, ^•ﻌ•^
    c-cwustewconfig::singwe, OwO
));

changing these settings wiww pwobabwy w-wesuwt in bad p-pewfowmance fow m-many games, outside of the specific scenawios d-descwibed above.