team-mount-ventoux / JayPS-WatchFace

JayPS (Pebble Bike/Ventoo) Watch Face
http://www.pebblebike.com
MIT License
22 stars 14 forks source link

Reduce mem using set_layer_attr function #7

Closed ron064 closed 10 years ago

ron064 commented 10 years ago

Using set_layer_attr reduces 508 bytes of code memory and increases available memory by same amount. (no change to used memory) Also reducing nearly 88 bytes from Debug version

Please check in regular user activity. Also double check two layers that have different alignment than center.

jay3 commented 10 years ago

Good job!

There is still some minor problems with at least color/backgroundcolor for some layers. I will check that.

ron064 commented 10 years ago

Sorry if I missed something. rechecking is a tiring task.

jay3 commented 10 years ago

I'm not sure why you don't send color, background_color and alignment to set_layer_attr. A way to save more memory? For future uses, it may be better to add them?

ron064 commented 10 years ago

if 10 times we are setting the same value and one time a different one, There is no use to send it as parameter every time. I didn't do full compare on how many times you need for it to be worth extra parameter. alignment is different from center only once or twice in the regular code, so I guessed it'd better to give default value and change it again afterward only in the needed place. I guess I missed that there are places with different background color.

ron064 commented 10 years ago

I tested two options:

  1. Restoring several lines of setting color. It added 44 bytes
  2. Adding function set_layer_attr_full adding setting 2 colors and alignment. It added 84 bytes. IMHO, The 2nd method is better from program structure perspective . What do you think?
jay3 commented 10 years ago

2nd version, with 40 extra bytes but better possibilities for the future, seems better. Thanks for your work! Le 27 avr. 2014 06:00, "ron064" notifications@github.com a écrit :

I tested two options:

  1. Restoring several lines of setting color. It added 44 bytes
  2. Adding function set_layer_attr_full adding setting 2 colors and alignment. It added 84 bytes. IMHO, The 2nd method is better from program structure perspective . What do you think?

Reply to this email directly or view it on GitHubhttps://github.com/pebble-bike/PebbleBike-PebbleWatchFace/pull/7#issuecomment-41487864 .

jay3 commented 10 years ago

I've tested another implementation of set_layer_attr_full() and save 164 bytes See https://github.com/jay3/PebbleBike-PebbleWatchFace/commit/0b542b801fb7f9519f7f5f34efccefb1372f76e5

ron064 commented 10 years ago

Sorry, I forgot to commit my updated version. my concept was heaving 2 function. the "full" is calling the shorter one. This way most of the places, you call the shorter function, and save memory, so only for more complicated text layers, you send all parameters. The total of this method would be 508-84 = 424. not clear to me if saved only 164 bytes or you reduced the save to 504-164. Anyway there is a limit to how much one can invest in it when gain is not very big.