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

Optimized memory usage #175

Merged
merged 1 commit into from
Mar 19, 2018
Merged

Conversation

janklimo
Copy link
Contributor

Following up on #173 I found some ways to make sanitize allocate less objects/memory (and added some basic Rubocop-driven cleanup).

The most effective change is that node_name is created only once in transform_node! (while previously it was allocated once per each transformer). In my quick test, this leads to significant savings.

Before
screen shot 2018-03-19 at 11 31 16 pm
screen shot 2018-03-19 at 11 31 28 pm
screen shot 2018-03-19 at 11 31 47 pm

After
screen shot 2018-03-19 at 11 34 46 pm
screen shot 2018-03-19 at 11 34 58 pm
screen shot 2018-03-19 at 11 35 15 pm

That amounts to 5.3MB less memory allocated, i.e. saving of ~16%.

@rgrove
Copy link
Owner

rgrove commented Mar 19, 2018

Nice! Thanks for digging into this. 👍

I'd like to merge the memory usage improvements, but I'm not interested in the style changes right now. Would you mind reverting those changes and leaving only the memory optimizations?

@janklimo janklimo force-pushed the optimize-memory-usage branch from ac980e4 to caa558a Compare March 19, 2018 18:18
@janklimo
Copy link
Contributor Author

You got it @rgrove 👍

@rgrove rgrove merged commit caa558a into rgrove:master Mar 19, 2018
@rgrove
Copy link
Owner

rgrove commented Mar 19, 2018

Merged and released as 4.6.2. 🍻

stanhu added a commit to stanhu/sanitize that referenced this pull request Jul 24, 2018
In 4.6.2, rgrove#175 significantly cut down on memory usage by caching the lowercase
version of the node name. However, as reported in rgrove#177, this broke certain
transformers that modified the node name since the name was cached. We can
bring back this optimization by updating the node name only if it has been
changed.

Closes rgrove#184
stanhu added a commit to stanhu/sanitize that referenced this pull request Jul 24, 2018
In 4.6.2, rgrove#175 significantly cut down on memory usage by caching the lowercase
version of the node name. However, as reported in rgrove#177, this broke certain
transformers that modified the node name since the name was cached. We can
bring back this optimization by updating the node name only if it has been
changed.

Closes rgrove#184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants