08_게임 물리 프로그래밍 가이드noerrorThis document provides an overview of physics engine usage for game physics programming. It introduces key concepts in physics such as kinematics, calculus, and numeric solutions. It also summarizes the Box2D and PhysX physics engines, including collision detection methods, constraints, joints and example code reviews. The goal is to provide background information for implementing physics in games without focusing on specific implementation details.
게임서버프로그래밍 #7 - 패킷핸들링 및 암호화Seungmo KooNHN NEXT 게임 서버 프로그래밍 강의 자료입니다. 최소한의 필요한 이론 내용은 질문 위주로 구성되어 있고 (답은 학생들 개별로 고민해와서 피드백 받는 방식) 해당 내용에 맞는 실습(구현) 과제가 포함되어 있습니다.
참고로, 서버 아키텍처에 관한 과목은 따로 있어서 본 강의에는 포함되어 있지 않습니다.
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기Chris Ohk"선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기"의 발표 자료입니다. 요즘 각광받고 있는 언어인 Rust로 여러 알고리즘 문제를 풀어보려는 분들에게 많은 도움이 되었으면 합니다.
Grapics debugging with RenderDocMatias Lavikݺߣs from my dev presentation at Dimension10.
The slides start with an introduction to RenderDoc, and is followed by 3 examples from real cases where RenderDoc saved my day.
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기Chris Ohk"선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기"의 발표 자료입니다. 요즘 각광받고 있는 언어인 Rust로 여러 알고리즘 문제를 풀어보려는 분들에게 많은 도움이 되었으면 합니다.
Grapics debugging with RenderDocMatias Lavikݺߣs from my dev presentation at Dimension10.
The slides start with an introduction to RenderDoc, and is followed by 3 examples from real cases where RenderDoc saved my day.
Dsl로 만나는 groovySeeyoung ChangThe document discusses Domain Specific Languages (DSLs) and how Groovy is well-suited for creating DSLs. It provides examples of DSLs like XML, HTML, and SQL. It then explains how Groovy features like dynamic typing, closures, meta-programming capabilities via metaclasses, and chaining methods allow it to easily define and implement DSLs. Specific Groovy DSL examples discussed include builders for XML/HTML, the GORM for object-relational mapping, and a Korean language DSL.
The state of PyPym_r_ePyPy is a fast runtime for Python.
It can speed up execution time up to 7x compared to normal CPython for sequential tasks.
Using a Just-In-Time compiler it has a similar approach as HHVM for PHP and Rubinius for Ruby.
This talks gives an overview of the current project goals, namely improving parallel execution speed with PyPy STM and improving C-Extension compatibility.
PyPySanghyeon SeoPyPy is a project that began in 2002 to create a Python interpreter written in Python. Over 10 years the project went through many stages of development including experimenting with different backends like LLVM and eventually achieving a breakthrough in 2005 where PyPy was able to run on its own after whole program type inference and translation to C. The document outlines key milestones and discussions in the development of PyPy over its first 10 years.
Baekjoon Online Judge 1451번 풀이Baekjoon ChoiThe document contains code snippets for solving problem 1451 on the Algorithm Problem Solving website acmicpc.net. It includes nested for loops calculating the sums of subsets in different ranges of a 2D array and updating the maximum value of their product. The code is testing all possible combinations of splitting the 2D space into three partitions.
Baekjoon Online Judge 10986번 풀이Baekjoon ChoiThe document describes an algorithm to solve a problem on an online judge platform. The problem involves counting the number of subarrays of integers whose sum is divisible by a given number M. The algorithm works by calculating a running sum of the integers, and checking if the remainder of the running sum modulo M is the same for any two indices, which would indicate the subarray between them has a sum divisible by M. It runs in O(N) time where N is the number of integers.
Baekjoon Online Judge 1201번 풀이Baekjoon ChoiThis document contains links to a problem on the Algorithm Problem Solving website Baekjoon and to a page about the Erdos-Szekeres theorem from MathWorld. It also lists examples of possible orderings for sets of numbers from 1 to 13 and suggests an alternative ordering.
Baekjoon Online Judge 1648번 풀이Baekjoon ChoiThe document contains multiple repetitions of a URL for a programming problem on acmicpc.net and grids of numbers. It links to the problem page on solving a chess knight's tour and shares a gist with sample code.
Baekjoon Online Judge 2873번 풀이Baekjoon ChoiThe document discusses a problem on the Algorithm Competition site acmicpc.net. It references problem 2873 multiple times and includes notes about the problem involving moving from a starting point (1,1) to an end point (R,C) on a grid. It also includes brief mentions of the size of the grid being 2x2 and variables A and B.
Baekjoon Online Judge 3015번 풀이Baekjoon ChoiThis document contains a series of lines that begin with "https://www.acmicpc.net/problem/3015" and are followed by various numbers, indicating a problem being solved on that website. It also includes several links to GitHub gists with code for solving the problem.
Baekjoon Online Judge 1019번 풀이Baekjoon ChoiThe document contains a series of links to the website https://www.acmicpc.net/problem/1019 and snippets of code related to counting the number of times each digit (0-9) appears when writing out an integer in base 10.
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015Jeongkyu ShinThis document discusses various Python and web development topics. It covers Python programming best practices and libraries like asyncio and NumPy. It also discusses front-end frameworks like Polymer and Electron. Additional sections provide overviews of containerization with Docker, message queues like ZeroMQ, log aggregation with Logstash, and cloud hosting options.
2014 ACM-ICPC Daejeon 인터넷 예선 해설Baekjoon ChoiThe document contains links to various coding challenge problems on the acmicpc.net problem-solving website. Code snippets and solutions are provided for problems related to sorting points by angle, convex hull algorithms, hashing, and dynamic programming. Overall it discusses algorithms and data structures for solving online judge problems.
2016317 파이썬기초_파이썬_다중설치부터_Jupyter를이용한프로그래밍_이태영Tae Young Lee1. pyenv를 이용한 파이썬 2, 파이썬 3 설치
2. Jupyter notebook에서 파이썬 2, 파이썬3 동시 이용
3. Jupyter notebook 사용법
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)Tae Young Lee파이썬 데이터과학 - 기초 과정(1일차)
- 데이터분석, 데이터시각화
- jupyter notebook, numpy, pandas, matplotlib, seaborn
2차 과정은 따로 올리겠습니다.
문의 및 제안 : se2n@naver.com
데이터 소스 : https://github.com/sh2orc/datascience
GDB와 strace로 Hang 걸린 Python Process 원격 디버깅Youngmin KooPython 프로그램을 디버깅하실 때 어떤 툴을 사용하시나요? 아무래도 가장 많이 사용하고 계신 툴은 PyCharm이 아닐까 싶습니다. PyCharm은 JetBrains에서 만든 GUI 환경에서 사용할 수 있는 Python IDE입니다.
PyCharm은:
로컬 컴퓨터에서 디버깅 모드로 (PyDev로) Python 프로세스를 실행할 수 있습니다.
로컬 컴퓨터에서 실행 중인 Python 프로세스에 Attach해 디버깅할 수 있습니다.
원격 서버에서 디버깅 모드로 (PyDev로) Python 프로세스를 실행할 수 있습니다.
하지만 원격에서 동작하고 있는 프로세스에 디버거를 Attach하는 기능은 제공하지 않고 있습니다. 또한 Python 디버깅 모듈인 pdb를 사용하여도 동작하고 있는 프로세스에 Attach하는 것은 지원하고 있지 않습니다.
로컬 환경에서는 문제 없이 돌아갔던 Python 프로그램이 원격 서버에서는 아무런 로그 없이 멈춰 버리는 경우 어디서부터 손을 대야 할지 정말 막막합니다. 이 때 GDB와 strace를 이용하면 어디에서 문제가 발생했는지 진단할 수 있습니다. 이 세션에서는 GDB와 strace를 이용해 디버깅하여 원격 리눅스 서버에서 Python Process가 Hang 되어 버리는 문제를 진단하고 해결했던 경험을 공유하려고 합니다.
파이썬 생존 안내서 (자막)Heungsub Lee넥슨코리아 사내 발표자료로 왓 스튜디오에서 파이썬으로 《야생의 땅: 듀랑고》 서버를 비롯한 여러가지 도구를 만든 경험을 공유합니다.
- 게임서버와 각종 툴, 테스트/빌드/배포 시스템을 만들 때 사용한 재료
- 파이썬 코드 품질 개선, 디버깅, 프로파일링, 최적화
- 파이썬 오픈소스 생태계와 왓 스튜디오가 하는 오픈소스 활동
1 Python기초 오리엔테이션cpt mobilex이 슬라이드는 창원대학교 정보통신공학과 mobile-x 학생들이 python을 주제로 2017년 하계 세미나를 진행한 내용입니다.
이 슬라이드는 오리엔테이션으로 총 6주 간의 세미나 계획과 python의 기본적인 설명을 담고있습니다.
(게임개발을위한) printf("Hello World!"); 그 이상의 콘솔 프로그래밍NDOORS일반적인 Visual 기반 프로그래밍 이외, 콘솔 프로그래밍의 필요성을 재조명하고자 합니다.
강연을 통해, Visual 기반 프로그래밍에 익숙해져 있는 (입문)개발자들에게, 콘솔 프로그래밍을 통해, 더욱 효과적으로 개발할 수 있도록 돕고자 합니다.
24. PyPy
• PyPy: (흔히) 파이썬으로 만들어진 파이썬 구현체
• CPython보다 빠르다던데?
• 파이썬으로 구현했는데 어떻게?
인터프리터를 만들 도구
25. PyPy
• PyPy: (흔히) 파이썬으로 만들어진 파이썬 구현체
• 인터프리터 작성을 위한 언어인 RPython
• RPython으로 작성된 파이썬 인터프리터
• PyPy는 두 가지를 *모두* 포함하는 프로젝트입니다
인터프리터를 만들 도구
26. PyPy
• PyPy: (흔히) 파이썬으로 만들어진 파이썬 구현체
• 인터프리터 작성을 위한 언어인 RPython
• RPython으로 작성된 파이썬 인터프리터
• PyPy는 두 가지를 *모두* 포함하는 프로젝트입니다
인터프리터를 만들 도구
27. RPython
• RPython: 정적으로 컴파일 되지만, 제약이 있는 파이썬
• 정적으로 컴파일 할 수 있는 코드만 지원합니다
• python2 의 부분집합(과 비슷)입니다
• 보너스! JIT 컴파일러 툴체인이 내장되어 있어요!
• 편리하고 강력한 언어로 빠르게 인터프리터를 만들어(RPython)
빠르게 실행(JIT)합니다. => PyPy
Restricted Python
28. JIT 컴파일러
• JIT 컴파일?
• 자주 사용되는 코드를 런타임에 추적해서,
• 최적화 후 컴파일 하여 실행시간에 바이너리를 생성합니다
• 런타임에만 알 수 있는 정보로 적극적인 최적화도 할 수 있어요
29. RPython
• RPython: 정적으로 컴파일 되지만, 제약이 있는 파이썬
• 제약이 있지만, C와 같은 언어보다 편리합니다.
• BigInt, Unicode 처리 등....
• RPython의 해당 기능을 이용하면 구현이 공짜!
Restricted Python
30. RPython
• RPython: 정적으로 컴파일 되지만, 제약이 있는 파이썬
• 게다가 JIT 컴파일러 툴체인이 내장되어 있다는데...
• CPython보다 PyPy가 더 빠른 비결
• 엄청나게 어려운 JIT 컴파일러 붙이기가 (거의) 공짜!
Restricted Python
32. PyPy, 얼마나 빠른가요?
• PyPy: 7.0x of CPython (2015)
• HippyVM: 7.3x of PHP / 2x of HHVM (2014)
33. PyPy, 얼마나 빠른가요?
• PyPy: 7.0x of CPython (2015)
• HippyVM: 7.3x of PHP / 2x of HHVM (2014)
• HHVM에 비해 적은 인원, 적은 코드로 더 좋은 성능
34. PyPy, 왜 빠른가요?
• RPython으로 인터프리터를 작성하고,
• 제공되는 툴체인으로 JIT를 하기 위한 힌트를 추가하면,
• 인터프리터가 실행추적 JIT로 변신!
35. PyPy, 왜 빠른가요?
• 실행추적(tracing) JIT
• 실용적으로 두 번째로 널리 쓰이는 JIT 기법입니다
• 실행추적 JIT는 실행시간에 추적한 루프 단위로 최적화합니다
• 전통적인 JIT
• 자주 함수되는 함수를 프로파일 해서 함수 단위로 컴파일합니다
36. 메타 실행추적 JIT
• RPython을 이용해 실행추적 JIT를 구현한다. (X)
• 인터프리터를 구현하면 실행추적 JIT의 효과를 낸다. (O)
• 어떤 인터프리터라도 (잘 손질하면) 변신!
• “메타”
37. – Arthur C. Clarke,
“Any sufficiently advanced technology is
indistinguishable from magic.”
38. 메타 실행추적 JIT
코드 읽기
실행
결과 저장
인터프리터
…
다음 코드로
JIT
루프 추적
최적화
컴파일
최적화 대상
직접 작성하는 부분JIT 생성기
39. 메타 실행추적 JIT
코드 읽기
실행
결과 저장
인터프리터
…
다음 코드로
JIT
루프 추적
최적화
컴파일
실행 코드
블랙박스
인터프리터 코드가 실행코드를 포함한 정보에 따라
최적화되어서 실행 코드를 최적화하는 효과 발생
40. PyPy, 왜 빠른가요?
• RPython: 메타 실행추적 JIT를 구현한 JIT 툴체인을 포함
• RPython으로 인터프리터를 구현하면
구현된 인터프리터에 실행추적 JIT 컴파일러를 적용합니다
• RPython으로 만들어진 파이썬(PyPy)은
컴파일된 인터프리터가 실행추적 JIT로 실행이 되고
따라서 이 인터프리터로 코드를 실행하면
인터프리터를 JIT하는 과정에서 코드 정보를 포함해서 최적화!
• HippyVM이 작은 코드로 HHVM보다 빨랐던 비결
42. 알파희
• 아희에 적용해 보자!
• (실행추적 JIT를 위해) 루프 추적을 도와주는 것이 핵심
• RPython으로 구현도 하고, RPython으로 구현하기 쉽게 다른
일도 조금 하고...
43. 알파희 1 - 전처리
• 2차원 언어는 런타임이 복잡해지므로 코드 분석 후 선형화
• 본심: RPython을 잘 모르니 가능하면 런타임을 작게 유지하자
• 밯망희
L0: PUSHCHAR ; 밯
BRPOP1 L4 ; ‘망’을 실행할 스택이
충분하지 않으면 L4
로 점프
POPNUM ; 망
HALT ; 희
L4: JMP L0 ;
44. 알파희 2 - 인터프리터
코드 읽기
실행
결과 저장
인터프리터
…
다음 코드로
JIT
루프 추적
최적화
컴파일
실행 코드
블랙박스
45. 알파희 2 - 인터프리터
• 직접 코드를 짜 넣을 부분
• 쉬워요! - 전처리 단계에서 귀찮은걸 많이 해결했으니까~
46. 알파희 2 - 인터프리터
# program: 직렬화된 아희 바이트코드의 리스트
def mainloop(program, debug):
s = Storage()
pc = 0
while pc < len(program): # 코드를 한 줄씩 실행
op, value = program[pc]
if op == OP_ADD:
r1, r2 = s.selected.pop(), s.selected.pop()
s.selected.push(r2 + r1)
elif op == OP_SUB:
…
47. 알파희 2 - 인터프리터
• ※ RPython으로 구현하기는 했지만 아직 JIT를 적용하기 전
$ rpython aheui.py # 컴파일 후 aheui-c 를 생성한다
$ time aheui-c logo.aheui => 23.5s
$ time caheui logo.aheui => 21.5s
• caheui보다 10% 정도 느린 정도로, 상당히 빠른 편
• “시작이 반이다” => 단순히 구현했을 뿐인데 이미 어느정도 빠르다!
• RPython은 파이썬 코드이지만, 네이티브 바이너리로 컴파일 가능하기 때문
48. 알파희 3 - JitDriver
코드 읽기
실행
결과 저장
인터프리터
…
다음 코드로
JIT
루프 추적
최적화
컴파일
실행 코드
블랙박스
50. 알파희 3 - JitDriver
from rpython.rlib.jit import JitDriver
driver = JitDriver(greens=['pc', 'program'], reds=['storage'])
def mainloop():
# initialization codes
pc = 0; storage = Stoarge()
while <cond>:
driver.jit_merge_point(
pc=pc, program=program, storage=storage)
<actual codes>
코드의 실행조건을 결정하는 상수 실행 결과 변경되는 산출물
루프 맨 앞에 삽입하는 것만으로 JIT 동작 시작!
51. 알파희 4 - 루프 추적
코드 읽기
실행
결과 저장
인터프리터
…
다음 코드로
JIT
루프 추적
최적화
컴파일
실행 코드
블랙박스
52. 알파희 4 - 루프 추적
• 루프 추적에 성공해야 최적화가 가능하다
1. green이 모두 같으면 같은 자리로 돌아온 것(루프)으로 판단
2. 같은 경로가 반복되면 최적화 시도
3. 가정이 맞는 동안 계속 최적화 된 코드를 실행
=> 가정이 깨진다면? 최적화에 실패하거나 최적화 된 코드를 버림
53. 알파희 4 - 루프 추적
• jit_merge_point: 핫루프 판단의 기준이 되는 기준점
• 규칙: jit_merge_point 앞에 나타나는 모든 변수는 green 또는
red로 표시해야 합니다
• 동작: green이 모두 일치하면 같은 문맥으로 간주합니다.
같은 문맥이 기준 이상 반복되면 핫루프로 간주합니다.
54. 알파희 4 - 루프 추적
• 이득: 최적화된 코드를 실행하는 만큼 실행 시간 이득을 얻습니다.
• 손실: jit_merge_point에서 코드를 추적하고 최적화를 시도하는
비용이 발생합니다. 최적화 이후에는 최적화된 코드가 올바른 코
드인지 점검하는 실행비용이 발생합니다.
55. 알파희 4 - 루프 추적
프로그램 (코드)
L0: PUSHCHAR
BRPOP1 L4
POPNUM
HALT
L4: JMP L0
프로그램 카운터
현재 코드: L0
메모리 (스택)
_: []
ㄱ: []
···
ㅎ: []
불변
변하지만
같은 값이면
같은 코드 실행
변하고
다른 값이어도
같은 코드 실행
green green red
56. 알파희 4 - 루프 추적
코드
L0: PUSHCHAR
BRPOP1 L4
POPNUM
HALT
L4: JMP L0
프로그램 카운터
현재 코드: L0
메모리 (스택)
_: []
ㄱ: []
···
ㅎ: []
불변
변하지만
같은 값이면
같은 코드 실행
변하고
다른 값이어도
같은 코드 실행
green green red
정말?
57. 알파희 4 - 루프 추적
x = 0
while True:
x += 1
if x < 1000000:
print ‘a’
else:
print ‘b’
<- 메모리에 해당하는 x가
코드 흐름에 영향
58. 알파희 4 - 루프 추적
• 저장공간은 정말 실행에 영향을 끼치지 않을까?
• 저장공간이 스택인지, 큐인지
• 저장공간에서 뽑아낼 값이 충분한지
• 저장공간의 변수가 비교문을 참으로 만드는지
• … 와 같은 이슈가 있지만, “아희”에 대해 파고 들지 말고 통과!
59. 알파희 5 - 루프 추적 최적화
• 기본 동작: 매 명령을 실행할 때마다 jit_merge_point에서 루프
를 찾으려 시도한다
• 수정: “루프가 될 수 있는 지점”을 힌트로 줘서 추적 비용을 줄인
다 (can_enter_jit)
• “루프가 될 수 있는 지점” = jump가 발생하는 지점
• ~= PC가 1씩 늘어나면 절대로 루프가 생기지 않으니까
60. 알파희 5 - 루프 추적 최적화
def mainloop(program, debug):
pc = 0; storage = init_storage()
while pc < program.size:
driver.jit_merge_point(pc=pc, proram=program)
op, operand = program[pc]
if needs_jump(op, operand, storage):
driver.can_enter_jit(pc=pc, program=program)
pc = operand
else:
# other operations
pc += 1
61. 알파희 5 - 루프 추적 최적화
밦밦따빠뚜
뿌뚜뻐뚜뻐
따ㅇㅇㅇ우
ㅇㅇ아ㅇ분
ㅇㅇ초뻐터
ㅇㅇ망희
……
L1: DUP ; L1 뻐
BRZ L6 ; L2 초
PUSH 2 ; L3 아 / 분
SUB ; L4 터
JMP L1 ; L5
L6: POPNUM ; L6 망
HALT ; L7 희
테스트 코드 선형화 코드
5개의 명령어를 반복한다
63. (기타 등등을 생략한) 결과
$ time AHEUI=../rpaheui/aheui-c ./test.sh logo/
real 0m1.795s
user 0m1.087s
sys 0m1.262s
$ time AHEUI=../caheui/aheui ./test.sh logo/
real 0m23.953s
user 0m23.843s
sys 0m0.058s
PyPy/RPython: 짧고 쉬운 코드로 빠른 인터프리터 완성!
64. 생략된 내용
• 작업 로그: https://github.com/aheui/rpaheui/blob/
master/LOG.md
65. 핵심
• PyPy 툴킷이 자동으로 붙여주는 JIT 컴파일러가 핫 루프를 찾아
내 가속합니다.
• 정확하게 찾도록 도와줍시다.
• 불필요하게 깐깐하면: 추적 비용이 증가
• 허술해서 guard가 틀리면: 최적화 비용 낭비
• 쉽게 찾도록 도와줍시다.