13. 핫스팟 찾기
A hot spot in computer science is most usually defined as a region of a computer program
where a high proportion of executed instructions occur or
where most time is spent during the program's execution
(not necessarily the same thing since some instructions are faster than others)
- Wikipedia -
14. 가장 문제가 되는 부분을 고치는 것이
일 한 티가 남 효율이 좋음
A:90 B:10
30 10
90 1
3x
10x
Amdahl's law
2x
15. 프로파일링!
In software engineering, profiling ("program profiling", "software profiling") is a form of
dynamic program analysis that measures, for example, the space (memory) or time complexity of a program,
the usage of particular instructions, or frequency and duration of function calls.
The most common use of profiling information is to aid program optimization.
- Wikipedia -
18. typedef vector<pair<int, string>> Scores;
void GetRanker(const Scores& l, Scores& r) {
// sort(list)[:3]
ScoreList m = l;
sort(m.begin(), m.end(), Scores_less);
r.assign(m.begin(), m.begin() + 3);
}
코드 최적화
디자인 최적화
19. 코드 최적화
void GetRanker(const Scores& l, Scores& r) {
vector<const Scores::value_type*> m(l.size());
for (size_t i=0, j=l.size(); i != j; ++i)
m[i] = &(l[i]);
sort(m.begin(), m.end(), pScoreList_less);
for (size_t i=0; i < 3; i++)
r.push_back(*m[i]);
}
4x
20. 디자인 최적화
void GetRanker(const Scores& l, Scores& r) {
// 리스트를 순회하며 가장 높은 점수 3개 찾기
for (auto i=l.begin(), j=l.end(); i != j; ++i) {
if (r.empty() || r.back().first < i->first) {
auto j = upper_bound(r.begin(), r.end(), *i);
r.insert(j, *i);
if (r.size() > 3)
r.pop_back();
}
}
}
+100x
21. 디자인
어셈블리
컴파일
코드
문제
탑랭커 3명 추려보이기
리스트를 정렬해 상위 3명 얻기
sort(list)[:3]
/Ox
예제
SIMD? PREFETCH?
임의로 뽑은 100명중 상위 3명
순회만으로 상위 3명 얻기
sort(&list)[:3]
/Ox /NO_DEBUG
최적화
x4
x100
x1000
x3
x2
23. CPU 프로파일러레벨
CodeAnalyst
VTune
Visual Studio Profiler
Very Sleepy
Glow Code
In-house Profiler
Brain
GPU 프로파일러
Perfhud
Perfstudio
GPA
PIX
X Engine Profiler
Eye
In-house Profiler
디자인
어셈블리
컴파일
코드
문제
40. item_map[0] = Item();
// item_map[0] – Item::Item() called
// Item() – Item::Item() called
// a = b – operator =
// ~Item() - Item()::~Item() called
Big Constructor & Map
49. ParseString(String) → Key, Value
ParseString(“Key1>테스트”) → “Key1”, “테스트”
ParseString
// 주석
Key1>테스트
Key2>개행도n됩니다n하하하
50. ParseString
길이 제한 검사 (strlen)
문자열 마지막의 ‘n’ ‘r’ 제거
문자열 앞 공백문자 건너뛰기
주석인지 검사
‘>’ 위치 찾기
키 길이 확인
‘>’ 앞뒤의 문자열 얻기 (string assign)
“n” 를 찾고 개행 문자로 치환
Key1>테스트문자열입니다
scan
scan
scan
alloc
59. ParseString 의 예
// 기존 함수와 새 함수가 동일한
// 결과를 반환하는지 확인
ParseString(line, key, val);
ParseStringNew(line, key2, val2);
ASSERT(key == key2 && val == val2);
67. 시작 시간 단축과 달리
매번 동일한 상황을 만들기 번거로우니 않으니.
F5 -> 게임 입장까지 절차 자동화
준비 (실행)
68. 프로파일러가 콜스택을 잘 보이도록
준비 (빌드 옵션)
• CL Global Optimization 끔
(켜 있으면 /Oy- 와 관계없이 FBO 가 되는 현상이 있음)
• CL Frame Buffer Omission 끔
(프로파일러가 콜 스택을 잘 보도록)
• LINK COMDAT Folding 끔
(Identical Function 이 합쳐지는 것 방지)
94. Allocator Guard
bool memcheck(byte* p, int len) {
dword* d = (dword*)p
dword* e = p + len / 4;
for (; d < e; ++d) {
if (*d != 0xabababab)
return false;
return true;
}
95. 몬스터간 충돌에 Kynapse 를 사용
Kynapse Collision
왜 원이 아니고 사각형인가?Collision_RectangularBody