Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
怖くないメモリ肥大化
Search
Tsukasa OISHI
October 31, 2024
Programming
1
52
怖くないメモリ肥大化
Nihonbashi.js #9のLTで発表しました。
Node.jsでのメモリ肥大化にどう対応するかというお話です。
Tsukasa OISHI
October 31, 2024
Tweet
Share
More Decks by Tsukasa OISHI
See All by Tsukasa OISHI
SLI/SLO をストリーム アラインドチームに導入した話
tsukasa_oishi
0
150
JITをたどるとそこはYARVの中
tsukasa_oishi
0
550
The Cacher in the Rye
tsukasa_oishi
1
5.8k
ISeqで遊ぼう
tsukasa_oishi
0
5k
Rubyを30倍速くした話
tsukasa_oishi
0
1.1k
はてブ砲をくらったときのお話
tsukasa_oishi
0
1.9k
食べログで動いている自作ライブラリのお話
tsukasa_oishi
0
290
奥さんとプログラミングを両立させる方法
tsukasa_oishi
0
50
MiyazakiResistanceを作ってみたよ
tsukasa_oishi
0
890
Other Decks in Programming
See All in Programming
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
CSC305 Lecture 26
javiergs
PRO
0
140
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Zoneless Testing
rainerhahnekamp
0
120
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
700
42 best practices for Symfony, a decade later
tucksaun
1
180
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
Go の GC の不得意な部分を克服したい
taiyow
2
770
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
1k
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Featured
See All Featured
Unsuck your backbone
ammeep
669
57k
Being A Developer After 40
akosma
87
590k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Building Your Own Lightsaber
phodgson
103
6.1k
GitHub's CSS Performance
jonrohan
1030
460k
Making Projects Easy
brettharned
116
5.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Mobile First: as difficult as doing things right
swwweet
222
9k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Thoughts on Productivity
jonyablonski
67
4.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Transcript
ා͘ͳ͍ ϝϞϦංେԽ
͓͓͍͔ͭ͠͞ !UTVLBTB@PJTIJ
'"5"-&33033FBDIFEIFBQMJNJU"MMPDBUJPOGBJMFE +BWB4DSJQUIFBQPVUPGNFNPSZ
ຊ൪͚ͩى͜ Δ
None
ຊ൪ͰϓϩϑΝ ΠϦϯά͢Δ͠ ͔ͳ͍
IUUQT[FOOEFWVCJF@EFWBSUJDMFTCGBFGF
͍͍ͩͨͷॴΛ ݟ͚ͭΔͷ͕ Ұ൪େมͳͷͰ ͜͜ΛΫϦΞͰ͖ͨΒ ͋ͱॗʑͱΔ͚ͩ
ᶃ
ςετ Λॻ͘
ᶄ
ίʔυ ΛಡΉ
($͕͔͔Βͳ͍ύλʔϯ
const cache: Map<string, any> = new Map(); άϩʔόϧมʹେ͖ͳσʔλঃʑʹ૿͑ΔσʔλΛ࣋ͨͤΔ
($͕͔͔ΔલʹώʔϓΛѹഭ͢Δύλʔϯ
ϧʔϓॲཧͰେྔͳΦϒδΣΫτΛੜ function generateLargeNumberOfObjects() { const objects: { id: number; data:
string }[] = []; for (let i = 0; i < 1000000; i++) { const obj = { id: i, data: ‘aaa….’ }; objects.push(obj); } return objects; }
ΫϩʔδϟʔͰ૿͑ΔσʔλΛอ࣋ function createDataAccumulator() { let data: number[] = []; return
function addData(newData: number): void { data.push(newData); }; } Const accumulateData = createDataAccumulator(); accumulateData(1); accumulateData(2); …
େ͖ͳσʔλΛҰʹѻ͏ const data = fs.readFileSync(filePath, 'utf8');
Կ͔ͷด͡Ε
const connection = mysql.createConnection({…}); connection.query('SELECT * FROM hoge_table’); // connection.end();
ࣗͨͪͷॻ͍ͨίʔυ͕ݪҼͳΒ ͍͍ͩͨίʔυಡΊݟ͔ͭΔ
ࣗͨͪͷॻ͍ͨίʔυͰͳ͍߹ ϓϩϑΝΠϥʔ͕ͳ͍ͱݫ͍͠
ྫ
None
νϟοτͷ ձ͕૿͑Δ ͱΤϥʔ
ɾຊ൪ڥͰͷΈൃੜ͢Δ ɹɾ,T.#ϝϞϦ ɾϩʔΧϧ։ൃڥͰϓϩηεͷϝϞϦݟͯ.#͘Β͍ ɹɾ.BD(#ϝϞϦ '"5"-&33033FBDIFEIFBQMJNJU"MMPDBUJPOGBJMFE +BWB4DSJQUIFBQPVUPGNFNPSZ
($
IFBQPVUPG NFNPSZ
NODE_OPTIONS=—max-old-space-size=250
const chatPrompt = ChatPromptTemplate.fromMessages([ [ "system", "You are a helpful
assistant that translates {input_language} to {output_language}.", ], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", “{text}"], … ["human", “{text}"], ]);
memoryCheck() { const heap = process.memoryUsage(); const msg = [];
for (const key in heap) { msg.push(`${key}: ${Math.round(heap[key] / 1024 / 1024)} MB`); } console.log(msg.join(', ')); }
start rss: 164 MB, heapTotal: 31 MB, heapUsed: 28 MB
end rss: 1137 MB, heapTotal: 999 MB, heapUsed: 959 MB
ίʔυେৎͦ͏
σόοΨʔ
ৄࡉهࣄʹ͋Γ·͢ IUUQT[FOOEFWVCJF@EFWBSUJDMFTGEE
export async function getEncoding( encoding: TiktokenEncoding, options?: { signal?: AbortSignal;
extendedSpecialTokens?: Record<string, number>; } ) { (লུ) return new Tiktoken( await cache[encoding], options?.extendedSpecialTokens ); }
start rss: 110 MB, heapTotal: 58 MB, heapUsed: 34 MB
end rss: 231 MB, heapTotal: 116 MB, heapUsed: 93 MB
None
·ͱΊ
ϓϩϑΝΠϥʔ Λ͑ΔΑ͏ʹ ͓ͯ͘͠
Α͋͘Δ ύλʔϯ Λ͓ͬͯ͘
࠶ݱςετ ͕ॻ͚Ε ҆৺
͓͠·͍