Last active
January 31, 2019 04:46
-
-
Save nemtsov/75806b9d32e908393c0f2fcab38fcfa7 to your computer and use it in GitHub Desktop.
Memory Leak Talk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const colors = ['red', 'green', 'blue']; | |
function getUserType(user) { | |
// - long or cpu-intensive task - | |
switch (user.color) { | |
case 'red': | |
return 'red user'; | |
case 'green': | |
return 'green user'; | |
case 'blue': | |
return 'blue user'; | |
} | |
} | |
const server = http.createServer((req, res) => { | |
const user = { | |
color: colors[Math.floor(Math.random() * 3)] | |
}; | |
res.end(getUserType(user)); | |
}); | |
server.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const colors = ['red', 'green', 'blue']; | |
const cache = {}; | |
function getUserType(user) { | |
// - long or cpu-intensive task - | |
switch (user.color) { | |
case 'red': | |
return 'red user'; | |
case 'green': | |
return 'green user'; | |
case 'blue': | |
return 'blue user'; | |
} | |
} | |
const server = http.createServer((req, res) => { | |
const user = { | |
color: colors[Math.floor(Math.random() * 3)] | |
}; | |
const cacheKey = JSON.stringify(user); | |
if (!cache[cacheKey]) { | |
cache[cacheKey] = getUserType(user); | |
} | |
res.end(cache[cacheKey]); | |
}); | |
server.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const crypto = require('crypto'); | |
const colors = ['red', 'green', 'blue']; | |
const cache = {}; | |
function getUserType(user) { | |
// - long or cpu-intensive task - | |
switch (user.color) { | |
case 'red': | |
return 'red user'; | |
case 'green': | |
return 'green user'; | |
case 'blue': | |
return 'blue user'; | |
} | |
} | |
const server = http.createServer((req, res) => { | |
const user = { | |
uid: crypto.randomBytes(10).toString('hex'), | |
color: colors[Math.floor(Math.random() * 3)] | |
}; | |
const cacheKey = JSON.stringify(user); | |
if (!cache[cacheKey]) { | |
cache[cacheKey] = getUserType(user); | |
} | |
res.end(cache[cacheKey]); | |
}); | |
server.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = {}; | |
setInterval(() => { | |
a[Math.random()] = true; | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment