Skip to content

Commit

Permalink
Round font sizes to the nearest tenth.
Browse files Browse the repository at this point in the history
Summary:
Using random font sizes explodes memory use because processing.js
caches PFont instances using the the font name and size as the cache
key.  Because the size is random, none of the cached font instances
are reused because we keep caching them.  A better solution would be
to use a LRU (Least Recently Used) cache like jscache.  If this continues
to be a problem we can look into changing the cache system.

Test Plan:
- open demos/simple/index.html in live-editor (in Firefox)  and type the following code:
```
    draw = function() {
        textSize(random(10,30));
    };
```
- check memory use using `top` or Activity Monitor and very that it tops out around 2GB (as opposed to continually growing)

Reviewers: pamela

Reviewed By: pamela

Subscribers: john

Differential Revision: https://phabricator.khanacademy.org/D19308
  • Loading branch information
kevinbarabash committed Jul 10, 2015
1 parent 2d8dc39 commit 56dd9f5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Expand Up @@ -15,7 +15,7 @@
url = https://github.com/Khan/structuredjs
[submodule "external/processing-js"]
path = external/processing-js
url = https://github.com/kevinb7/processing-js
url = https://github.com/Khan/processing-js
[submodule "external/escodegen"]
path = external/escodegen
url = https://github.com/Khan/escodegen
Expand Down
2 changes: 2 additions & 0 deletions build/js/live-editor.output_pjs_deps.js
Expand Up @@ -16321,6 +16321,8 @@
*/
p.textSize = function(size) {
if (size !== curTextSize) {
// round size to the nearest tenth so that we don't explode the cache
size = Math.round(10 * size) / 10;
curTextFont = PFont.get(curFontName, size);
curTextSize = size;
// recache metrics
Expand Down
2 changes: 1 addition & 1 deletion external/processing-js
Submodule processing-js updated 1 files
+2 −0 processing.js

0 comments on commit 56dd9f5

Please sign in to comment.