-
Notifications
You must be signed in to change notification settings - Fork 28
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
Change String not to be reassigned #428
Conversation
I think this change is something that should be considered. WDYT? @ydah |
Memory usageVerification Procedure
diff --git a/Gemfile b/Gemfile
index 9ae5b9fd48..5af7508578 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,6 +8,7 @@ gem "rake"
gem "rspec"
gem "simplecov", require: false
gem "stackprof", platforms: [:ruby] # stackprof doesn't support Windows
+gem "memory_profiler"
# Recent steep requires Ruby >= 3.0.0.
# Then skip install on some CI jobs.
diff --git a/exe/lrama b/exe/lrama
index ba5fb06c82..f697492921 100755
--- a/exe/lrama
+++ b/exe/lrama
@@ -2,5 +2,8 @@
$LOAD_PATH << File.join(__dir__, "../lib")
require "lrama"
-
-Lrama::Command.new.run(ARGV.dup)
+require 'memory_profiler'
+report = MemoryProfiler.report do
+ Lrama::Command.new.run(ARGV.dup)
+end
+report.pretty_print
ruby tool/id2token.rb parse.y > parse.tmp.y
cp parse.tmp.y dir/lrama/tmp
SummaryBefore
After
Full ReportMuch of the memory appears to be used by lexer.rb. From an overall perspective, there does not appear to be that much change. Full ReportBefore ``` Total allocated: 3302455861 bytes (6836404 objects) Total retained: 592 bytes (4 objects)allocated memory by gem3300045820 lrama/lib allocated memory by file2960603032 /ydah/lrama/lib/lrama/lexer.rb allocated memory by location1336343436 /ydah/lrama/lib/lrama/lexer.rb:147 allocated memory by class2959325947 String allocated objects by gem6812590 lrama/lib allocated objects by file2814507 /ydah/lrama/lib/lrama/bitmap.rb allocated objects by location1334165 /ydah/lrama/lib/lrama/bitmap.rb:20 allocated objects by class2916389 Integer retained memory by gem
retained memory by file
retained memory by location
retained memory by class
retained objects by gem
retained objects by file
retained objects by location
retained objects by class
Allocated String Report
Retained String Report
Total allocated: 3310825264 bytes (7009251 objects) allocated memory by gem3308414383 lrama/lib allocated memory by file2960994352 /ydah/lrama/lib/lrama/lexer.rb allocated memory by location1336343436 /ydah/lrama/lib/lrama/lexer.rb:145 allocated memory by class2967047062 String allocated objects by gem6985417 lrama/lib allocated objects by file2814507 /ydah/lrama/lib/lrama/bitmap.rb allocated objects by location1334165 /ydah/lrama/lib/lrama/bitmap.rb:18 allocated objects by class2916389 Integer retained memory by gem
retained memory by file
retained memory by location
retained memory by class
retained objects by gem
retained objects by file
retained objects by location
retained objects by class
Allocated String Report
Retained String Report
|
Execution speedMeasured using stackprof.
$ ruby tool/id2token.rb parse.y > parse.tmp.y
$ cp parse.tmp.y dir/lrama/tmp
diff --git a/exe/lrama b/exe/lrama
index ba5fb06..2497178 100755
--- a/exe/lrama
+++ b/exe/lrama
@@ -3,4 +3,6 @@
$LOAD_PATH << File.join(__dir__, "../lib")
require "lrama"
-Lrama::Command.new.run(ARGV.dup)
+Lrama::Report::Profile.report_profile do
+ Lrama::Command.new.run(ARGV.dup)
+end Before
After
|
Follow up: ruby#424
Thank you! I measured each before and after. I verified and there seems to be no significant deterioration. |
I see. Both memory usage and execution time have increased. However, it seems that the Lexer/Parser still dominates both memory usage and execution time, and Output is not the bottleneck. This level of increase appears to be acceptable. Thank you for the measurements. |
Follow up: #424