Skip to content

Chris' Laboratory

chrislee.kr – Personal blog as bookshelves

Menu
  • Home
  • Github
  • Contact Me
Menu

Designing for Performance

Posted on 01/01/201109/04/2011 by Chris Lee
Read Time:2 Minute, 14 Second

Reference: http://developer.android.com/guide/practices/design/performance.html

성능을 위한 디자인
* 기본적으로 할수있다면 임시 객체를 생성하는것을 최대한 피하라. 생성된 객체가 적을 수록 UX(User Experience)에 직접적인 영향을 미치는 가비지 콜렉션(Garbage Collection)이 적게 실행된다.
1. 객체 생성을 피하라
– 입력 데이터에서 문자열을 추출할때, 복사본을 만드는 대신에, 원본 데이터 문자열의 부분만 리턴하여라. String 객체를 만들어야 하겠지만, 그 객체는 원본데이터와 char[]를 공유할 것이다.
– 만약 문자열을 리턴하는 메쏘드가 있고, 그 결과가 항상 StringBuffer에 추가된다면, 임시 객체를 생성하는 대신에 해당 함수가 직접 추가하도록 소스 코드와 프로세스를 수정하여라(의역: change your signature and implementation)
– Integer 배열보다 int 배열이 더 좋다. 그리고 두개의 int 배열들이 (int, int) 객체 배열보다 더 효과적이다. 이 이론은 기본 형(Primitive Type)의 조합에도 적용된다.
– 만약 (Foo, Bar)객체들의 배열(Tuples)를 저장하는 컨테이너(Container)를 구현해야한다면, Custom 객체 (Foo, Bar)의 배열보다는 Foo[]와 Bar[] 배열들이 더 효율적이다.
2. Performance Myths
Previous versions of this document made various misleading claims. We address some of them here.
On devices without a JIT, it is true that invoking methods via a variable with an exact type rather than an interface is slightly more efficient. (So, for example, it was cheaper to invoke methods on a HashMap map than a Map map, even though in both cases the map was a HashMap.) It was not the case that this was 2x slower; the actual difference was more like 6% slower. Furthermore, the JIT makes the two effectively indistinguishable.
On devices without a JIT, caching field accesses is about 20% faster than repeatedly accesssing the field. With a JIT, field access costs about the same as local access, so this isn’t a worthwhile optimization unless you feel it makes your code easier to read. (This is true of final, static, and static final fields too.)
3. Virtual보다 static을 선호하여라
– 객체의 필드에 접근할 필요가 없다면, 당신의 메쏘드를 static으로 만들어라. Static 메쏘드들의 호출은 15%-20% 빨리진다. 메쏘드 시그니쳐(Method Signature)로부터 객체의 상태를 변경시킬수 없는 함수를 호출한다는 것을 알 수 있기 때문에, 이는 또한 좋은 개발방법론이다.
4. 내부 Getters/Setters를 피하라
– C++같은 원시 언어들은, i = mCount 같이 객체에 바로 접근하는 것보다 보통 getters (예제. i = getCount())를 사용한다.
– 안드로이드 프로그래밍에서는 가상 메쏘드를 호출하는 것은 비효율적이기 때문에, 이는 안좋은 방법이다.
– 외부 함수에서는 getters/setter를 사용하지만, 클라스 내부에서는 객체에 직접 접근하라.
5. 상수(Constants)에 Static Final 를 이용하라.
static final int intVal = 42;
static final String strVal = "Hello, world!";
6. 강화된 반복문 문법을 이용하여라
– 제일 빠른 아이.
   public void two() {
        int sum = 0;
        for (Foo a : mArray) {
            sum += a.mSplat;
        }
    }
7. Int 값들을 위하여 Enums를 사용하지 말아라.
8. 내부 함수들에게 패키지 범위(Package Scope)를 사용하여라
9. 적절한 Floating-Point를 사용하라
10. 라이브러리들을 이용하여라.
11. 적절한 네이티브 메쏘드들을 이용하여라.

Share

Facebook
Twitter
LinkedIn
Email

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • Databases (11)
    • MongoDB (4)
    • MS-SQL (1)
    • MySQL (6)
  • E-Commerce (8)
    • Magento (8)
  • Finance (2)
  • Frameworks (84)
    • Adobe Flex (1)
    • Angular (ngx) (3)
    • Codeigniter (6)
    • CSS (5)
    • Django (2)
    • Javascript (13)
    • Node.js (6)
    • PHP (17)
    • React Native (4)
    • React.js (1)
    • Sencha Touch (4)
    • Terraform (1)
    • Vue.js (1)
    • WordPress (4)
    • Yii2 (3)
  • General Documents (15)
  • Marketing (3)
  • Mobile Development (33)
    • Android (20)
    • iPhone (13)
  • Platforms (21)
    • Arduino (2)
    • Docker (5)
    • Google App Engine (5)
    • Raspberry Pi (5)
    • Samsung Smart TV (4)
  • Security (17)
  • Server (31)
    • Linux (13)
  • Tools (14)
    • SVN (7)
  • Uncategorized (3)

Search

Recent Posts

  • helm list error stream ID 3; INTERNAL_ERROR
  • Bootstrapping Kubernetes cluster with kubeadm
  • Taint all resources in the one module
  • Alpine – Plugin caching_sha2_password could not be loaded
  • npm link with peerDependencies

Recent Comments

  • Obayed on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Ari on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Mida ali on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Chris Lee on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Chris Lee on Setting Up A VPN Server On OSX 10.6

Tags

1 ajax amazon android android-addpart browser chrislee-kr codeigniter codeigniter-tcpdf com-apple-net-racoon CSS CSS history hack delpaigmail-com entity-addpart-double exception-printing-is-disabled-by-default-for-security-reasons ext-plugins-listpagingplugin ext-plugins-listpagingplugin-example f iphone javascript jquery-defaultchecked jquery-samsung-smart-tv listpagingplugin mac magento-exception-printing-is-disabled-by-default-for-security-reasons magento-sample-data-exception-printing-is-disabled-by-default-for-security-reasons nu-vot null-core-errors-confignotfound-config-mk9engine-ini php samsung-smart-tv-jquery samsung-smart-tv-sdk-ajax samsung-smart-tv-sdk-jquery samsung-tv-sdk samsung-tv-sdk-jquery samsung tv sencha-smart-tv sencha-touch-list-paging smart-tv-jquery sqlite subversion svn tcedook tcpdf-codeigniter uilinebreakmodecharacterwrap-is-deprecated unknown-column-link-area

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2023 Chris' Laboratory | Powered by Minimalist Blog WordPress Theme