# Writing TypeScript on a laptop? This might improve your battery life.


Two things happened recently:

* My laptop’s battery was draining out too fast.

* I began learning [TypeScript](https://www.typescriptlang.org/).

I’m using `tsc` (TypeScript’s compiler) in [watch mode](https://www.typescriptlang.org/docs/handbook/compiler-options.html) which is very convenient to trigger automatic transpilation while developing.

But here’s what happens:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1632308566078/aKmfihhpc.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1632308567579/CmcrifIFn.png)

Node (which the TypeScript compiler runs on) is eating 8% of CPU cycles just while sitting down waiting for file changes. WOW.

A quick digging around pointed me to this link: [https://github.com/Microsoft/TypeScript/pull/8196/](https://github.com/Microsoft/TypeScript/pull/8196/)

Apparently `tsc` reverted to a polling approach to watch for file changes which appears to be quite resource intensive. They made this choice because the non-polling approach used previously turned out to be slow at detecting file changes in many cases.

### But not all hope is lost!

Luckily the non-polling file watcher is still in the code and can be enabled by setting this environment variable: `TSC_NONPOLLING_WATCHER="1"` .

So now watch this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1632308569256/GYQ0aa1JP.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1632308570606/uH3yn9QUh.png)

Now it is like it should be: No file changes, no CPU usage.

Up until now I did not notice any laziness at detecting file changes on a 2016 MacBook Pro 13" running mac OS 10.12.2 and the battery life got a big improvement since then.

Hope this helps.

Marco
