pkaminski / digest-hud

Digest performance analysis HUD for AngularJS.
MIT License
111 stars 20 forks source link

Enable later in the lifecycle #18

Open sebastian-zarzycki-apzumi opened 7 years ago

sebastian-zarzycki-apzumi commented 7 years ago

Would it be possible to shift the actual enabling later on in the application cycle? The performance/stats enabling is usually decided upon initialization, driven by some values, etc. etc. If possible, I would prefer to be able to enable it later, from controller or component (in my own "if" block). In the config section I don't have yet access/data to be able to determine if I want to enable it or not. Adding and removing code doesn't sound like a good idea.

pkaminski commented 7 years ago

I don't think it's possible to delay enabling since it needs to decorate a bunch of built-in services to capture data, and this can only happen at config time. It would be possible to show/hide the widget itself later, but you'd still be paying for the instrumentation overhead regardless. It might also be possible to tweak the instrumentation so that it's minimally intrusive unless enabled later. If you want to give this a try and find it to work fine, I'd be happy to review and integrate.

Otherwise, I recommend getting your config values ready earlier in the bootstrap cycle. One trick you can use is filling in a .constant (which is available in the config phase) with an IIFE that parses out query params like ?debug=digest. Another idea is to generate such constant definition code as part of your build, depending on whether you're targeting dev or prod.