typicode / hotel

🏩 A simple process manager for developers. Start apps from your browser and access them using local domains
MIT License
9.98k stars 422 forks source link

Enable view template caching #195

Closed fengb closed 7 years ago

fengb commented 7 years ago

This change caches view templates in memory:

# Current
$ time curl -s localhost:2000 >/dev/null
real    0m0.058s

# After change
$ time curl -s localhost:2000 >/dev/null
real    0m0.021s

Alternatively, this can be enabled by setting NODE_ENV=production but I couldn't figure out how to generate a plist with the environment variable.

typicode commented 7 years ago

Hi,

You can update nodemon.json to set NODE_ENV to development and enable or not caching based on that. https://github.com/remy/nodemon/blob/be5d4e8d13a6dcc16c65b5bce59edef54496a8ae/doc/sample-nodemon.md

fengb commented 7 years ago

I tried that but the performance was similar to before the explicit cache enable.

fengb commented 7 years ago

Oh, this cache should be enabled for daemon mode, which doesn't use nodemon:

<array>
  <string>/opt/nodes/7.6.0/bin/node</string>
  <string>/Users/fengb/.config/yarn/global/node_modules/hotel/lib/daemon</string>
</array>
typicode commented 7 years ago

I see, actually if it's too complicated I wouldn't bother too much.

Even though it's a nice catch :+1:, the benefit is just 0.02 seconds which is unnoticeable and the daemon is just run locally. For a public website it would definitely make sense though.

I'm curious if this can work?

// daemon-prod.js
process.env.NODE_ENV = 'production'
require('./') // src/daemon/index.js
fengb commented 7 years ago

My intent is to speed up proxied requests. I believe the browser will hit the proxy on every request so the 20-30ms will add up:

image

fengb commented 7 years ago

Actually, I remember needing to refresh my browser's proxy so it's probably not per request. Since the rest of the app doesn't use the view layer, this is probably not needed.

Thanks for your quick replies!