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
61
怖くないメモリ肥大化
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
2k
食べログで動いている自作ライブラリのお話
tsukasa_oishi
0
300
奥さんとプログラミングを両立させる方法
tsukasa_oishi
0
52
MiyazakiResistanceを作ってみたよ
tsukasa_oishi
0
910
Other Decks in Programming
See All in Programming
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
290
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
420
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.4k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
100
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
2.8k
2025.01.17_Sansan × DMM.swift
riofujimon
2
560
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.3k
ドメインイベント増えすぎ問題
h0r15h0
2
570
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
170
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
64k
Automating Front-end Workflow
addyosmani
1366
200k
For a Future-Friendly Web
brad_frost
176
9.5k
YesSQL, Process and Tooling at Scale
rocio
170
14k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Why Our Code Smells
bkeepers
PRO
335
57k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Scaling GitHub
holman
459
140k
Faster Mobile Websites
deanohume
305
30k
We Have a Design System, Now What?
morganepeng
51
7.3k
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
·ͱΊ
ϓϩϑΝΠϥʔ Λ͑ΔΑ͏ʹ ͓ͯ͘͠
Α͋͘Δ ύλʔϯ Λ͓ͬͯ͘
࠶ݱςετ ͕ॻ͚Ε ҆৺
͓͠·͍