Nasal Events: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 32: Line 32:
Problem is, lot's of Nasal modules listen to the property /sim/signals/fdm-initialized to trigger some initialization code. It's fine to do so. However, modules need to be aware that this signal triggers on _every_ simulator reset. So, the connected code executes every time you hit Shift-ESC, use the "Relocate-in-air" or "Relocate-on-ground" dialogs.
Problem is, lot's of Nasal modules listen to the property /sim/signals/fdm-initialized to trigger some initialization code. It's fine to do so. However, modules need to be aware that this signal triggers on _every_ simulator reset. So, the connected code executes every time you hit Shift-ESC, use the "Relocate-in-air" or "Relocate-on-ground" dialogs.


We had plenty of places were init code connected to "/sim/signals/fdm-initialized" installed a fresh set of listeners or started another timer-driven update loop. This results in performance degrading with every sim reset.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg36668.html|title=[Flightgear-devel] Performance issue with sim reset vs Nasal|author=ThorstenB|date=Tue, 20 Mar 2012 13:52:37 -0700}}</ref>|ThorstenB}}
We had plenty of places were init code connected to "/sim/signals/fdm-initialized" installed a fresh set of listeners or started another timer-driven update loop. This results in performance degrading with every sim reset.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg36668.html|title=<nowiki>[Flightgear-devel]</nowiki> Performance issue with sim reset vs Nasal|author=ThorstenB|date=Tue, 20 Mar 2012 13:52:37 -0700}}</ref>|ThorstenB}}


{{cquote|the main purpose of the event manager is to handle Nasal's settimer() code. So you better look for slow recurring Nasal code.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31593.html|title=Re: [Flightgear-devel] Stuttering at 1 Hz rate|author=Melchior FRANZ|date=Thu, 24 Mar 2011 05:39:15 -0700}}</ref>|Melchior FRANZ}}
{{cquote|the main purpose of the event manager is to handle Nasal's settimer() code. So you better look for slow recurring Nasal code.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31593.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> Stuttering at 1 Hz rate|author=Melchior FRANZ|date=Thu, 24 Mar 2011 05:39:15 -0700}}</ref>|Melchior FRANZ}}


{{cquote|Any Nasal timer, even if it's almost empty, will every now and then consume a much larger amount of time than normal.
{{cquote|Any Nasal timer, even if it's almost empty, will every now and then consume a much larger amount of time than normal.
Seems to be a general issue with the Nasal execution engine: could be triggered by Nasal's garbage collector, which every now and then needs  
Seems to be a general issue with the Nasal execution engine: could be triggered by Nasal's garbage collector, which every now and then needs  
to do extra work - and runs within the context of a normal Nasal call. It could also be a result of Nasal's critical sections: other threads  
to do extra work - and runs within the context of a normal Nasal call. It could also be a result of Nasal's critical sections: other threads  
may acquire a temporary lock to alter Nasal data structures - which may block the execution of Nasal timers at certain points.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31610.html|title=Re: [Flightgear-devel] Stuttering at 1 Hz rate|author=ThorstenB|date=Thu, 24 Mar 2011 16:39:34 -0700}}</ref>|ThorstenB}}
may acquire a temporary lock to alter Nasal data structures - which may block the execution of Nasal timers at certain points.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31610.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> Stuttering at 1 Hz rate|author=ThorstenB|date=Thu, 24 Mar 2011 16:39:34 -0700}}</ref>|ThorstenB}}




{{cquote|When evaluating simulation performance, don't get fooled by the frame rate. What's really important to us is the "worst case frame latency".
{{cquote|When evaluating simulation performance, don't get fooled by the frame rate. What's really important to us is the "worst case frame latency".
Even if the system is producing a huge average of 100 frames per second, it can still look absolutely crappy, if only a single frame took more than 20-30ms, since that's immediately visible to the human eye (note to self: add a "worst case latency" indicator). So, we're building a real-time system here, and 20-30ms is our timing constraint.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31652.html|title=Re: [Flightgear-devel] Stuttering at 1 Hz rate|author=ThorstenB|date=Sun, 27 Mar 2011 13:31:16 -0700}}</ref>|ThorstenB}}
Even if the system is producing a huge average of 100 frames per second, it can still look absolutely crappy, if only a single frame took more than 20-30ms, since that's immediately visible to the human eye (note to self: add a "worst case latency" indicator). So, we're building a real-time system here, and 20-30ms is our timing constraint.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31652.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> Stuttering at 1 Hz rate|author=ThorstenB|date=Sun, 27 Mar 2011 13:31:16 -0700}}</ref>|ThorstenB}}


{{cquote|Nasal needs to run a garbage collection every now and then. This means an extra delay, and may become noticeable, if it causes a frame to
{{cquote|Nasal needs to run a garbage collection every now and then. This means an extra delay, and may become noticeable, if it causes a frame to
Line 51: Line 51:
properties of the code. If we can keep the delay below the limit, everything is perfect. If we cannot, than we should at least reduce
properties of the code. If we can keep the delay below the limit, everything is perfect. If we cannot, than we should at least reduce
its frequency. One stutter per minute may be acceptable. Once every second looks absolutely intolerable (though you may still get a funky
its frequency. One stutter per minute may be acceptable. Once every second looks absolutely intolerable (though you may still get a funky
100fps indication!).<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31652.html|title=Re: [Flightgear-devel] Stuttering at 1 Hz rate|author=ThorstenB|date=Sun, 27 Mar 2011 13:31:16 -0700}}</ref>|ThorstenB}}
100fps indication!).<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31652.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> Stuttering at 1 Hz rate|author=ThorstenB|date=Sun, 27 Mar 2011 13:31:16 -0700}}</ref>|ThorstenB}}


{{cquote|There's several timers which run at full frame rate, even when the related feature is disabled:
{{cquote|There's several timers which run at full frame rate, even when the related feature is disabled:
Line 60: Line 60:
fgdata/Nasal/track_target.nas:194
fgdata/Nasal/track_target.nas:194


Even when they're almost doing nothing, it'd still help if they were stopped or at least slowed down, when the related feature was disabled. They affect garbage collection since a lot of (useless) contexts are created and need to be cleared at some point - hence triggering the g/c more often than necessary.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31652.html|title=Re: [Flightgear-devel] Stuttering at 1 Hz rate|author=ThorstenB|date=Sun, 27 Mar 2011 13:31:16 -0700}}</ref>|ThorstenB}}
Even when they're almost doing nothing, it'd still help if they were stopped or at least slowed down, when the related feature was disabled. They affect garbage collection since a lot of (useless) contexts are created and need to be cleared at some point - hence triggering the g/c more often than necessary.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31652.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> Stuttering at 1 Hz rate|author=ThorstenB|date=Sun, 27 Mar 2011 13:31:16 -0700}}</ref>|ThorstenB}}


{{cquote|A bit background on the FG subsystems may be necessary though to really judge what's going on. For example, you'll see the "nasal" subsystem consuming almost no time at all, so it looks great. However, almost all the nasal code runs in timers, and timers are driven by the "events" subsystem. So, to judge Nasal performance, you'll mainly need to look at "events" (and yes, you'll see time being consumed and jitters being produced there).<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg34886.html|title=[Flightgear-devel] New performance statistics GUI|author=ThorstenB|date=Sat, 19 Nov 2011 08:22:52 -0800}}</ref>|ThorstenB}}
{{cquote|A bit background on the FG subsystems may be necessary though to really judge what's going on. For example, you'll see the "nasal" subsystem consuming almost no time at all, so it looks great. However, almost all the nasal code runs in timers, and timers are driven by the "events" subsystem. So, to judge Nasal performance, you'll mainly need to look at "events" (and yes, you'll see time being consumed and jitters being produced there).<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg34886.html|title=<nowiki>[Flightgear-devel]</nowiki> New performance statistics GUI|author=ThorstenB|date=Sat, 19 Nov 2011 08:22:52 -0800}}</ref>|ThorstenB}}


{{cquote|The event manager handles timers, and that's almost exclusively used by Nasal. Almost all the Nasal code runs in timers (except for property listeners). So read "events" as the total execution time for Nasal (timers). The timing data shown for the subsystem "nasal" only refers to the execution time of Nasal internal house keeping (i.e. some garbage collection), but not to the execution of actual Nasal code. Indeed misleading.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31604.html|title=Re: [Flightgear-devel] Stuttering at 1 Hz rate|author=ThorstenB|date=Thu, 24 Mar 2011 11:45:40 -0700}}</ref>|ThorstenB}}
{{cquote|The event manager handles timers, and that's almost exclusively used by Nasal. Almost all the Nasal code runs in timers (except for property listeners). So read "events" as the total execution time for Nasal (timers). The timing data shown for the subsystem "nasal" only refers to the execution time of Nasal internal house keeping (i.e. some garbage collection), but not to the execution of actual Nasal code. Indeed misleading.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg31604.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> Stuttering at 1 Hz rate|author=ThorstenB|date=Thu, 24 Mar 2011 11:45:40 -0700}}</ref>|ThorstenB}}


{{cquote|Only dialogs which regularly trigger a full redraw (using Nasal timers) cause significant issues. The performance dialog uses "live" properties, so no dialog redraw is required while it stays open. Only the "sort" button triggers a full redraw, hence a jitter. This is why the sort is triggered with a manual button so far, rather than by a periodic timer - the latter had completely spoiled statistics.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg34896.html|title=Re: [Flightgear-devel] New performance statistics GUI|author=ThorstenB|date=Sat, 19 Nov 2011 14:05:40 -0800}}</ref>|ThorstenB}}
{{cquote|Only dialogs which regularly trigger a full redraw (using Nasal timers) cause significant issues. The performance dialog uses "live" properties, so no dialog redraw is required while it stays open. Only the "sort" button triggers a full redraw, hence a jitter. This is why the sort is triggered with a manual button so far, rather than by a periodic timer - the latter had completely spoiled statistics.<ref>{{cite web |url=http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg34896.html|title=Re: <nowiki>[Flightgear-devel]</nowiki> New performance statistics GUI|author=ThorstenB|date=Sat, 19 Nov 2011 14:05:40 -0800}}</ref>|ThorstenB}}




<references/>
<references/>
[[Category:Developer Plans]]
[[Category:Developer Plans]]

Navigation menu