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
Python Memory Management
Search
Junseong
December 15, 2021
0
670
Python Memory Management
2021.12.15 스캐터랩 엔지니어링 세미나에서 발표한 Python Memory Management 발표자료 입니다.
Junseong
December 15, 2021
Tweet
Share
More Decks by Junseong
See All by Junseong
House Share Platfrom with Senior Citizen 👵🏻🏠 - Junction Asia 2023
codertimo
0
78
Haru - Diary App with Stable Diffusion (JUNCTION 2022)
codertimo
0
1.8k
Imaginar.AI - JUNCTION ASIA 2022 Hackathon
codertimo
0
2.4k
[파이콘 2019] 100억건의 카카오톡 데이터로 똑똑한 일상대화 인공지능 만들기
codertimo
7
3.9k
All you need is Google's AI Tech: I/O Extended Seoul 2019
codertimo
1
400
[네이버 테크톡] 사람들과 자연스러운 대화를 나누는 인공지능 '핑퐁' 만들기
codertimo
0
370
“머신러닝 엔지니어가 다녀온 F8” 김준성 - F8 2019 Meetup:Seoul
codertimo
0
200
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.8k
Automating Front-end Workflow
addyosmani
1366
200k
KATA
mclloyd
29
14k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
400
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Six Lessons from altMBA
skipperchong
27
3.5k
Faster Mobile Websites
deanohume
305
30k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Transcript
Python Memory Management ӣળࢿ (ML Research Engineer, Pingpong)
Python Memory Management ޖट ੌ ੌযզө?
Python Memory Management Name, Reference, Object 10 A name Reference
Object
Python Memory Management ޖट ੌ ੌযզө?
Python Memory Management Reference Count 10 A Reference Object B
Reference Count: 2 ࢜۽ чਸ Memory ী Allocation ೞח Ѫ ইצ ӝઓ Object ী Reference ୶о
Python Memory Management Delete Variable
Python Memory Management Reference Count 10 A Object B Reference
Count: 1 (-1) पઁ A Object о Dealloc غח Ѫ ইצ Reference ݅ ઁ
Python Memory Management if Reference Count == 0
Python Memory Management if Reference Count == 0 10 A
Object B Reference Count: 0 (-1) -> deallocation
Python Memory Management п ёо न Reference Count ܳ ٜҊ
Ҋ, ೧ Count о 0 غݶ dealloc
Python Memory Management Ӓۢ Garbage Collection ਃ হחѢ ইצоৈ??
ࢎप Python ীࢲח ਤ җਸ Reference Count based GC ۄҊ ࠗܰҊ णפ.
Cyclic Reference GC ઁݾ ఫझ
Python Memory Management ޖट ੌ ੌযզө?
[L] Python Memory Management Recursive Reference L Object Reference Count:
2 ۠ ࣽജ ଵઑ غয ח ҃ Reference Count ܳ ӝ߈ਵ۽ ೠ Deallocation ࠛоמೞ
[L] Python Memory Management Cyclic Reference L Object Reference Count:
1 : Name L ਸ ਕب ࣽജଵઑ غয ӝ ٸޙী Reference Count ח 0 غ ঋח => Memory Leak!
Python Memory Management GC for Cyclic Reference Python ীࢲ GCח
Cyclic Reference ܳ dealloc ೞחؘ ౠചغয णפ.
Python Memory Management GC for Cyclic Reference
Foo(0) Python Memory Management GC for Cyclic Reference A Object
Next Foo(1) B Next Foo(0) Ref Count : 2 Foo(1) Ref Count : 2
Python Memory Management GC Reference Count Object Reference Count GC_Reference
Count Reason Foo(0) 2 2 copy(refCnt) Foo(1) 2 2 copy(refCnt)
Python Memory Management Automated Garbage Collection Object Reference Count GC_Reference
Count Reason Foo(0) 2 1 Foo(1).next.gcRefCnt -= 1 Foo(1) 2 1 Foo(0).next.gcRefCnt -= 1 Nothing Happened!
Python Memory Management GC for Cyclic Reference
Foo(0) Python Memory Management GC for Cyclic Reference A Next
Foo(1) B Next Foo(0) Ref Count : 1 Foo(1) Ref Count : 1
Python Memory Management GC Reference Count Object Reference Count GC_Reference
Count Reason Foo(1) 1 1 copy(ref_count) Foo(2) 1 1 copy(ref_count) Reference Count ч Deep Copy
Python Memory Management GC Reference Count Object Reference Count GC_Reference
Count Reason Foo(0) 1 0 Foo(1).next.gcRefCnt -= 1 Foo(1) 1 0 Foo(0).next.gcRefCnt -= 1
Python Memory Management Cyclic Reference ী ೠ GC ࢿҕ!! Object
Reference Count GC_Reference Count Reason Foo(0) 1 0 Foo(1).next.gcRefCnt -= 1 Foo(1) 1 0 Foo(0).next.gcRefCnt -= 1 Dealloc Dealloc
GIL: Global Interpreter Lock Python Memory Management
Pythonਵ۽ ѐߊೞח ഥࢎٜ ױҎ ݶ ޙઁ > ॆীࢲ GIL ަөਃ?
Python Memory Management
Python Memory Management
Python Memory Management ୨ 3ѐ Reference Count о хࣗ غযঠ
ೞחؘ, Ѿҗਵ۽ח 2ѐ݅ хࣗؽ -> Race Condition Ѿҗਵ۽ memory leak ਸ ߊࢤदఃѢա ߈۽ ই ইযঠ ೡ objectܳ લৈߡܾ ࣻب .
Python Memory Management Ѧ ߑೞ۰ݶ ݽٚ Reference Count Operation ী
Lock ਸ Ѧݶ ؽ ೞ݅ Python Ѣ ݽٚ Operation ীࢲ Reference Count ܳ ೞӝ ٸޙী ח ষդ ࠺ബਯࢿਸ оઉ১
Python Memory Management Reference Counting ਸ ӝ߈ਵ۽ ೠ GC ܳ
ࢎਊೞח ҃ Thread-Safe ೧ঠ ೣ Ӓ Ѿҗ GIL ߆ী উ হח Ѫ…. -> Ӓېࢲ Java ח Mark and Sweep ߑध GC ܳ ࢎਊפ Ѥ ܲ ࠙..^^7
Python Memory Management
Python Memory Management ࢎप ݫݽܻ ҕрী ҙೠ ղਊب חؘ.. -
Pool, Block, Arena, Generation ١١… ۞р ೞܖઙੌ ೧ঠ ೧ࢲ ӝഥী..ƃƃ
Python Memory Management ࠗ۾: ৵ Python String Overhead о
חо? ॆ ‘ч’ۄח ѐ֛ হ ݽٚ Object - Reference Count - Type Info - Char Array (value) - Intern ച غয ח ৈࠗ - String Object Hash ч
хࢎפ✌ ୶о ޙ ژח ҾӘೠ ݶ ઁٚ ইې োۅ۽
োۅ ࣁਃ! ӣળࢿ (ML Research Engineer, Pingpong)
[email protected]
Facebook. @codertimo Linked in. @codertimo Github. @codertimo