Improving Nasal: Difference between revisions

Jump to navigation Jump to search
m
Line 80: Line 80:
* Time other parts of Nasal (not just VM) with a compile-time flag? (could be stored in the Context struct, so that sub contexts would have their own flags, i.e. recursive scripts would not affect each other)
* Time other parts of Nasal (not just VM) with a compile-time flag? (could be stored in the Context struct, so that sub contexts would have their own flags, i.e. recursive scripts would not affect each other)
* Also, add some form of Context-based debug/log-level flag for different verbosity levels and phases (parse,codegen,vm,gc) - and maybe don't write it directly to the console, but allow a container/callback to be specified - for better integration/processing by the host app (fgfs)
* Also, add some form of Context-based debug/log-level flag for different verbosity levels and phases (parse,codegen,vm,gc) - and maybe don't write it directly to the console, but allow a container/callback to be specified - for better integration/processing by the host app (fgfs)
* Better error messages {{Progressbar|30}}.
* Better error messages {{Progressbar|30}}.
** '''Parsing:''' Say something other than "parse error", like "null pointer".
** '''Parsing:''' Say something other than "parse error", like "null pointer".
** '''VM:''' Indicate type of variable if wrong type.
** '''VM:''' Indicate type of variable if wrong type.
Line 90: Line 90:
** Optimize: not started (it makes only sense to look at optimizations after we're able to instrument/profile a running FG session to come up with hot spots that are executed either frequently, or that are responsible for significant runtime overhead - i.e. due to GC pressure or other issues)
** Optimize: not started (it makes only sense to look at optimizations after we're able to instrument/profile a running FG session to come up with hot spots that are executed either frequently, or that are responsible for significant runtime overhead - i.e. due to GC pressure or other issues)
** Working with it: provide Bytecode class in Nasal: not started<!-- (the exposeOpcode() API already exists, most other machinery could be built in scripting space on top of it?)-->
** Working with it: provide Bytecode class in Nasal: not started<!-- (the exposeOpcode() API already exists, most other machinery could be built in scripting space on top of it?)-->
* Inspect Context: not started, should be easy.
* Inspect Context: {{Progressbar|80}} (passed as argument to callbacks).
* Expose Tokens to Nasal: implemented by Hooray as argument to compile(), should be extended to cover output from lex.c and after blocking in addition to the current after-prec-ing (and before freeing!) support. {{Progressbar|70}}
* Expose Tokens to Nasal: implemented by Hooray as argument to compile(), should be extended to cover output from lex.c and after blocking in addition to the current after-prec-ing (and before freeing!) support. {{Progressbar|70}}
** compile() being used by call(), it should be straightforward to also map a call() hash.callback to do the same thing here - so that there's no disparity here.
** compile() being used by call(), it should be straightforward to also map a call() hash.callback to do the same thing here - so that there's no disparity here.
Line 98: Line 98:
** Option 2: recognize assignment in the VM and if there is a bindToContext event, set the name of the function based upon either the last LOCAL/MEMBER/HINSERT or the combination of them (i.e. complex lvalues like local.fn). This presents some obvious issues, however:
** Option 2: recognize assignment in the VM and if there is a bindToContext event, set the name of the function based upon either the last LOCAL/MEMBER/HINSERT or the combination of them (i.e. complex lvalues like local.fn). This presents some obvious issues, however:
*** The right-hand side of an assignment is done before the left-hand side, thus one would have to look ahead to see the assignment, which is clearly illegal for the VM to do.
*** The right-hand side of an assignment is done before the left-hand side, thus one would have to look ahead to see the assignment, which is clearly illegal for the VM to do.
*** Or one could look behind to see a naCode constant being pushed, and give some indication to its naFunc that it now has a name. This I still somewhat illegal, but not dangerous and thus could be done.
*** Or one could look behind to see a naCode constant being pushed, and give some indication to its naFunc that it now has a name. This is still somewhat illegal, but not dangerous and thus could be done.
*** how is this supposed to deal with multiple symbols aliasing the same function ?
** Option 3: abandon <tt>var foo = func(){}</tt> for ECMAscript-like function declaration syntax <tt>function foo() {}</tt>. This would not affect the use of anonymous func expressions but would instead be applicable in cases where we want to say "this function is static (i.e. permanent) and should have a name" (as opposed the the case of temporary storage variables for functions). Regardless of the method used, a name member will have to be added to naFunc's and the VM and error handling procedures will have to be changed according.
** Option 3: abandon <tt>var foo = func(){}</tt> for ECMAscript-like function declaration syntax <tt>function foo() {}</tt>. This would not affect the use of anonymous func expressions but would instead be applicable in cases where we want to say "this function is static (i.e. permanent) and should have a name" (as opposed the the case of temporary storage variables for functions). Regardless of the method used, a name member will have to be added to naFunc's and the VM and error handling procedures will have to be changed according.
** Regarding the last comment: Providing an API to "lock" a symbol/naRef to become immutable would be generally useful, not just for functions - but also for constants (math.pi FT2M etc) and other stuff that may otherwise break consistency - ThorstenR mentioned a couple of times how he's intentionally replicating standard constants in LW/AW just to be on the safe side, because there's no such thing as a "constant" in Nasal. Providing a library function to make naRefs read-only should be straightforward, and could be easily implemented by hooking into the VM to register a callback that yields naRuntimeError() -aka die()- for any such attempts. The method would be scalable to also implement optional typing or min/max/stepping (value ranges), too
** Regarding the last comment: Providing an API to "lock" a symbol/naRef to become immutable would be generally useful, not just for functions - but also for constants (math.pi FT2M etc) and other stuff that may otherwise break consistency - ThorstenR mentioned a couple of times how he's intentionally replicating standard constants in LW/AW just to be on the safe side, because there's no such thing as a "constant" in Nasal. Providing a library function to make naRefs read-only should be straightforward, and could be easily implemented by hooking into the VM to register a callback that yields naRuntimeError() -aka die()- for any such attempts. The method would be scalable to also implement optional typing or min/max/stepping (value ranges), too.
** This should be doable, since I do a naRuntimeError(ctx,naGetError(subcontext)) which ''should'' pass errors from a callback (untested).
** This should be doable, since I do a naRuntimeError(ctx,naGetError(subcontext)) which ''should'' pass errors from a callback (untested).
** To implement support for immutable symbols (constants/ private/protected encapsulation), one would really just need to either lock WRITE access or  
** To implement support for immutable symbols (constants/ private/protected encapsulation), one would really just need to either lock WRITE access or restrict visibility, which could work analogous to parents, just as embedded protected/private hashes that are honored by the codegen.
restrict visibility, which could work analogous to parents, just as embedded protected/private hashes that are honored by the codegen.
* Getting stats on Nasal performance while running: use the callbacks and systime to time things. Need hooks into the GC as well. Statistics worth tracking (also look at similar tools like [http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html google perftools]):
* Timing parts of VM: use the callbacks and systime/unix.time to time things. Need hooks into the GC as well. Statistics worth tracking (also look at similar tools like [http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html google perftools]):
** Per function (also handles timers/listeners and other typical FG callbacks):
** Per function (also handles timers/listeners and other typical FG callbacks):
*** ncalls per frame/cumulative
*** ncalls per frame/cumulative
*** time per call on avg/cumulative
*** time per call (kept as list) {{Done}} – display min/max/avg/cumulative.
*** min/max time
*** number of GC invocations & avg/min/max time
*** number of GC invocations & avg/min/max time
*** number of naNew() calls
*** number of naNew() calls
*** number & list of names of once-use variables; n that are numbers (i.e. non-GC-managed).
*** number & list of names of once-use variables {{Done}}; n that are numbers (i.e. non-GC-managed).
*** try to come up with heuristics to track *identical* temporaries per callback invocation: [[User:Philosopher/Howto:Write Optimized Nasal Code]]
*** try to come up with heuristics to track *identical* temporaries per callback invocation: [[User:Philosopher/Howto:Write Optimized Nasal Code]]
*** maybe some holistic "GC pressure" percentage over time (5,30,60,300 seconds ?)
*** maybe some holistic "GC pressure" percentage over time (5,30,60,300 seconds ?)
*** GC pressure can be computed by looking not just at new allocations, but also at realloc() events and the mark/reap phases
*** GC pressure can be computed by looking not just at new allocations, but also at realloc() events and the mark/reap phases
*** for GC stats, we can also easily access 1) size of all allocated naType pools and 2) percentage that's in use and 3) newBlock() allocations
*** for GC stats, we can also easily access 1) size of all allocated naType pools and 2) percentage that's in use and 3) newBlock() allocations
** Per context/global:
** Per context/global:
*** time spent
*** time spent
395

edits

Navigation menu