pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.62k stars 519 forks source link

Profiling #277

Open Aidiakapi opened 10 years ago

Aidiakapi commented 10 years ago

When it comes to performance Lua is an odd bird. It's hybrid table implementation and all strings being interned makes it hard to sometimes see where the lost time is.

For performance testing it'd be great to have a profiler available. After all, first measure, then optimize.

I realize there are some Lua libraries for profiling out there, but they're mostly cumbersome to use, not flexible, and most essentially, not very accurate. I'm quite positive that in C(++), an implementation could be much better.

pkulchenko commented 10 years ago

There are two ways I've considered for this: (1) integration with LuaJIT profiler since ZBS includes LuaJIT by default, and (2) Lua only profiler. The obvious benefit of (2) is that it works with any engine, while the obvious disadvantage is that its accuracy can be quite off as it's based on debug.hook. The main disadvantage of (1) is that you may not want to rely on it if your engine is not LuaJIT-based, but it should still be a good way to identify bottlenecks and you can run it with jit.off to make it execution to be closer to "normal" Lua.

The interesting part is how to present the profiling results to make it useful and well integrated with the IDE. I'm open to suggestions...

pkulchenko commented 9 years ago

Proof of concept: https://github.com/CapsAdmin/zbprofiler

abigpotostew commented 8 years ago

@pkulchenko Is that a heat diagram for percentage of overall time? I would also consider adding the number of times a line is run and related metrics.

pkulchenko commented 8 years ago

@abigpotostew, yes, but there is a limited number of gradations as it's done with markers and there are only few of them in the editor. Yes, number of times a line is run would be interesting to add as well.

gschenck commented 8 years ago

Take a look at http://howl.io/blog/2016/05/26/introducing-aullar.html#aullar as a replacement (?) for Scintillia.

pkulchenko commented 8 years ago

@gschenck, it's not related to this ticket, but I'll answer it briefly. I definitely follow Howl with interest and carefully reviewed their rationale for switching away from Scintilla. Here is why some of that rationale doesn't apply to this project:

  1. Implementation of better indicators (flairs in Howl terminology) has been added to Scintilla 3.5.3 and included in the current version of the IDE under development.
  2. Support for flexible lexing (including embedded lexers) will be available with the included support for LexLPEG (from Scintillua). It's also based on LPEG, so similar in may aspects to what Howl is doing.
  3. Removing a dependency and keeping all development in one language (plus reduced executable size) is more important to Howl than to this project as we still need to use wxwidgets, which is a much larger library than the (already included in it) Scintilla library.
  4. Transparency and variable height styles, while visually interesting, do not warrant the current component to be replaced.
  5. This project is using some of the Scintilla functionality that is not used (and as the results is not available) in Howl, for example, invisible styles, which are used in markdown formatting in comments.
pkulchenko commented 7 years ago

Couple of notes on this: ProFi profiler, sampling profiler for Lua 5.3, interactive continuous Python profiler, profile format used by DProf, and couple of screenshots from Unreal profiler: 1 and 2.