Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservableItemが使用するメモリ量が多い #247

Closed
fukudayasuo opened this issue Sep 26, 2013 · 1 comment
Closed

ObservableItemが使用するメモリ量が多い #247

fukudayasuo opened this issue Sep 26, 2013 · 1 comment
Assignees
Milestone

Comments

@fukudayasuo
Copy link

ObservableItemの作成するFWコードを見直す。
ObservableItemはDataModelと共通した処理を同じ個所で行うために、DataModelで作成するDataItemコンストラクタを利用しており、ObservableItemを作成するたびにDataItem生成のためのコンストラクタを作成し、ObservableItemからそのコンストラクタが参照できるようになっている。

そのため、ObservableItem1つにつきDataModel1つと同じくらいのメモリを使用していると考えられる。

とりあえず、ObservableItemを作るときにDataItemコンストラクタを作成して使用するのはそのままにして、そのコンストラクタがObservableItemから参照できない(使いきり)になるようにする。

// 現在のcreateObservableItem
// コンストラクタを新規に生成してをそれをnewして返している
return new (createDataItemConstructor(schema, itemValueCheckFuncs))();

// これを以下のように変更
var item =  new (createDataItemConstructor(schema, itemValueCheckFuncs))();
return new ObservableItem(item);

//...
function ObservableItem(item){
// itemから必要なプロパティをコピー
this[prop] = item[prop];
...
}
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue Sep 26, 2013
ObservableItemのコンストラクタを作成し、各ObservableItem共通のものはObservableItem.prototypeに持たせるようにリファクタしました。
@ghost ghost assigned fukudayasuo Sep 26, 2013
@fukudayasuo
Copy link
Author

今までObservableItemそれぞれのコンストラクタを作っていたものを、ObservableItemクラスを作成して共通のものをprototypeに持たせるようにしました。

内部ではそれぞれのコンストラクタを作成してObservableItemのインスタンス作成に使用していますが、外から参照はされません。

以下のコードでObservableItemによるメモリの使用量を測定したところ、3.06MB→1.00MBに減りました。

// 1000個のObservableItemを作成してview.bind()
$('body').append( ' <div id="result" data-h5-loop-context="data">    <div data-h5-bind="message"></div>  </div>');
var infoItems = h5.core.data.createObservableArray();
h5.core.view.bind('#result', {data:infoItems});

for (var i = 0; i < 1000; i++) {
  var item = h5.core.data.createObservableItem({
    message: {
      type: 'number'
    }
  });
  item.set('message', i);
  infoItems.unshift(item);
}

fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue Sep 26, 2013
hasOwnPropertyなものと、schemaとschemaInfoの中身をコピーするようにしました。
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue Sep 26, 2013
_originModelを使用するのをやめて_modelは常に生成時のDataModelが格納されるようにしました。削除されたかどうかは_isRemovedプロパティを追加してそれを見るようにしました。
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue Sep 26, 2013
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue Sep 30, 2013
createObservable時にdepend.calcが呼ばれたときにthisの値がObservableItemではなく内部で使用しているDataItemになっていましたので、修正しました。
テストケースの追加もしました。
@simdy simdy added this to the v1.1.9 milestone Feb 24, 2014
@simdy simdy closed this as completed Feb 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants