Skip to content

Conversation

makspll
Copy link
Owner

@makspll makspll commented Aug 31, 2025

Summary

  • ScriptContext API Changes: Now wrapped in Arc<RwLock<>> - access via .read() and .write() methods; get() renamed to get_context(); New methods: get_resident(), get_context_and_residency()
  • HandlerContext Removed: No longer available - replaced by direct access to ScriptContext; with_handler_system_state() function removed
  • CallContext Trait: New trait implemented for all script contexts; Provides call_context_dynamic() and call_context() methods
  • GetPluginFor Trait: All context types must now implement this trait; Provides reverse mapping from context to plugin type
  • Lua Type Changes: Context type changed from mlua::Lua to LuaContext wrapper; Update all code interacting with Lua contexts
  • RunScriptCallback Changes: run_with_handler() replaced with run_with_context() and run_with_contexts()
  • Script Creation/Reloading: Completely restructured script lifecycle methods; New granular API for different script creation/update scenarios

Migration GUide

  • ScriptContext Access: Use .read() and .write() to access ScriptContext (now wrapped in Arc<RwLock<>>); replace get() with get_context()
  • HandlerContext: Replace with direct ScriptContext access; remove any with_handler_system_state() calls
  • Script Callbacks: Use new call_context_dynamic() or call_context() methods from the CallContext trait
  • Custom Context Types: Implement the new GetPluginFor trait to provide mapping from context to plugin type
  • Lua Interaction: Replace mlua::Lua with LuaContext wrapper type in all Lua code
  • Script Callback Running: Replace run_with_handler() calls with run_with_context() or run_with_contexts()

@makspll makspll enabled auto-merge (squash) August 31, 2025 01:50
Copy link
Contributor

github-actions bot commented Aug 31, 2025

🐰 Bencher Report

Branchrefactor/remove-handler-context
Testbedlinux-gha

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
component/access LuaLatency
microseconds (µs)
📈 plot
🚷 threshold
🚨 alert (🔔)
4.58 µs
(+11.58%)Baseline: 4.10 µs
4.58 µs
(100.07%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
component/access Lua📈 view plot
🚷 view threshold
🚨 view alert (🔔)
4,578.90 ns
(+11.58%)Baseline: 4,103.69 ns
4,575.71 ns
(100.07%)

component/access Rhai📈 view plot
🚷 view threshold
5,594.50 ns
(-4.72%)Baseline: 5,871.93 ns
6,291.96 ns
(88.92%)
component/get Lua📈 view plot
🚷 view threshold
2,251.40 ns
(-7.61%)Baseline: 2,436.89 ns
2,710.27 ns
(83.07%)
component/get Rhai📈 view plot
🚷 view threshold
4,255.20 ns
(-3.22%)Baseline: 4,396.75 ns
4,823.06 ns
(88.23%)
conversions/Mut::from📈 view plot
🚷 view threshold
80.27 ns
(-7.03%)Baseline: 86.33 ns
93.65 ns
(85.71%)
conversions/Ref::from📈 view plot
🚷 view threshold
78.44 ns
(-6.54%)Baseline: 83.93 ns
89.88 ns
(87.27%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
283.25 ns
(+0.50%)Baseline: 281.84 ns
320.70 ns
(88.32%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
1,260.20 ns
(+5.20%)Baseline: 1,197.92 ns
1,583.89 ns
(79.56%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
26.14 ns
(+7.27%)Baseline: 24.37 ns
28.14 ns
(92.90%)
conversions/Val::from_into📈 view plot
🚷 view threshold
370.23 ns
(+20.02%)Baseline: 308.47 ns
386.16 ns
(95.88%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,559.70 ns
(-16.45%)Baseline: 1,866.72 ns
2,192.85 ns
(71.13%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,381.40 ns
(-10.57%)Baseline: 1,544.62 ns
1,769.89 ns
(78.05%)
function/call Lua📈 view plot
🚷 view threshold
233.93 ns
(-3.56%)Baseline: 242.56 ns
265.09 ns
(88.25%)
function/call Rhai📈 view plot
🚷 view threshold
394.94 ns
(-14.84%)Baseline: 463.74 ns
543.12 ns
(72.72%)
loading/empty Lua📈 view plot
🚷 view threshold
52,868.00 ns
(-17.31%)Baseline: 63,933.50 ns
74,687.35 ns
(70.79%)
loading/empty Rhai📈 view plot
🚷 view threshold
382,290.00 ns
(+0.97%)Baseline: 378,624.00 ns
442,936.40 ns
(86.31%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
7,434.40 ns
(-3.58%)Baseline: 7,710.31 ns
8,834.31 ns
(84.15%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,062.80 ns
(-9.41%)Baseline: 6,692.90 ns
7,513.32 ns
(80.69%)
query/10 entities Lua📈 view plot
🚷 view threshold
19,652.00 ns
(-6.06%)Baseline: 20,920.00 ns
22,805.01 ns
(86.17%)
query/10 entities Rhai📈 view plot
🚷 view threshold
19,079.00 ns
(-8.10%)Baseline: 20,759.60 ns
23,069.95 ns
(82.70%)
query/100 entities Lua📈 view plot
🚷 view threshold
41,918.00 ns
(-2.38%)Baseline: 42,938.80 ns
44,792.43 ns
(93.58%)
query/100 entities Rhai📈 view plot
🚷 view threshold
34,992.00 ns
(+4.56%)Baseline: 33,466.60 ns
36,050.22 ns
(97.06%)
query/1000 entities Lua📈 view plot
🚷 view threshold
287,850.00 ns
(+2.24%)Baseline: 281,530.00 ns
301,720.88 ns
(95.40%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
189,380.00 ns
(+9.53%)Baseline: 172,900.00 ns
193,010.23 ns
(98.12%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,487.40 ns
(-11.50%)Baseline: 6,200.43 ns
6,974.00 ns
(78.68%)
reflection/10 Rhai📈 view plot
🚷 view threshold
15,378.00 ns
(-3.67%)Baseline: 15,964.10 ns
16,851.28 ns
(91.26%)
reflection/100 Lua📈 view plot
🚷 view threshold
45,468.00 ns
(-11.15%)Baseline: 51,174.40 ns
57,958.34 ns
(78.45%)
reflection/100 Rhai📈 view plot
🚷 view threshold
744,080.00 ns
(-2.75%)Baseline: 765,102.00 ns
829,802.67 ns
(89.67%)
resource/access Lua📈 view plot
🚷 view threshold
3,920.20 ns
(+7.02%)Baseline: 3,663.18 ns
3,983.46 ns
(98.41%)
resource/access Rhai📈 view plot
🚷 view threshold
5,117.60 ns
(-4.28%)Baseline: 5,346.15 ns
5,752.75 ns
(88.96%)
resource/get Lua📈 view plot
🚷 view threshold
1,862.40 ns
(-10.21%)Baseline: 2,074.12 ns
2,350.33 ns
(79.24%)
resource/get Rhai📈 view plot
🚷 view threshold
3,818.60 ns
(-2.55%)Baseline: 3,918.52 ns
4,334.51 ns
(88.10%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll merged commit 421fc0d into main Aug 31, 2025
27 of 30 checks passed
@makspll makspll deleted the refactor/remove-handler-context branch August 31, 2025 02:31
@github-actions github-actions bot mentioned this pull request Aug 31, 2025
@github-actions github-actions bot mentioned this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant