Giter Site home page Giter Site logo

buschtoens / ember-dead-code Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 0.0 156 KB

Detect dead code with confidence via real user monitoring

License: MIT License

JavaScript 77.59% HTML 22.41%
ember emberjs ember-addon ember-cli ember-cli-addon real-user-monitoring dead-code-removal dead-code-elimination

ember-dead-code's Introduction

ember-dead-code

Build Status npm version Download Total code style: prettier
Ember Observer Score Ember Versions ember-cli Versions
Dependabot enabled dependencies devDependencies

Detects dead code with confidence via real user monitoring. Finds dead components, routes, helpers, ember-intl translations and whatever your heart desires!

The Idea

JavaScript is a dynamic language and notoriously hard to statically analyze. While it is easy to detect that a certain file or piece of code is used, detecting that it is not used is really hard. The fact that components and helpers don't get invoked through JavaScript, but Handlebars, and might even have interpolated names, makes this virtually impossible.

False positives are dangerous, as they could lead to deletions that turn up weeks later in production, because of some weird edge-case scenario that has not been accounted for in the analysis.

So instead of doing the hard work ourselves, why don't we let our users do the work in production for us?

ember-dead-code hooks into the central resolver, logs all lookups and periodically reports them to your backend in batches. This technique is called Real User Monitoring.

The longer you collect data, the more confident you can become that your list of code that is in-use is complete. You can then feed this report back into ember-dead-code and let it remove dead code for you.

Installation & Setup

ember install ember-dead-code

Development Status

So far this is just an idea and not functional yet. This repo exists so that we can already talk about the concept and review some code.

FAQ

Why run it in production? Can I not collect this data in my acceptance tests?

There's two problems. If your (acceptance) tests do not cover 100 % of your codebase, ember-dead-code will incorrectly report code as dead that is actually in use in production. And if your tests do cover 100 % of your codebase, ember-dead-code can incorrectly report code that is dead in production as still in-use.

You get the most reliable results by monitoring actual production usage.

Won't this have a negative performance impact?

The ember-resolver is a central piece to every Ember app and a very hot code path. Hooking into it and doing a lot of synchronous work would of course degrade performance noticeably.

This is why we try very hard to make the actual data collection as efficient and lightweight as possible. The only thing we do inside the resolver is pushing the requested lookup specifier, e.g. service:foo, into a shared Set, if natively supported, or plain array otherwise.

We then run a task approx. every n seconds (you can configure that value!) that deduplicates lookup logs and reports them to the backend, when a configurable threshold batch size is reached.

If available, we use requestIdleCallback for this to minimize the noticeable performance impact even further. Otherwise we use later.

How long do I need to collect data?

YMMV. This depends on the size and behavioral patterns of your user base. We recommend collecting data for at least two weeks, before drawing any conclusions. The longer you wait, the more confident you can be in deleting code.

We also recommend to never stop collecting data. Dead code is an inevitability. As your codebase evolves over time, you will always forget to remove chunks of code. It's nice to have some piece of mind, knowing that your dead code will be reported eventually.

ember-dead-code's People

Contributors

buschtoens avatar ember-tomster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.