-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Compiler: Add "Top 10 slowest modules" to --stats output #12942
Open
z64
wants to merge
2
commits into
crystal-lang:master
Choose a base branch
from
z64:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Compiler: Add "Top 10 slowest modules" to --stats output
- Loading branch information
commit bfafd46d1bcc4e8985131d346edea8a7e6c60fdd
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,19 +470,31 @@ module Crystal | |
pr, pw = IO.pipe | ||
spawn do | ||
pr.each_line do |line| | ||
unit = JSON.parse(line) | ||
reused << unit["name"].as_s if unit["reused"].as_bool | ||
unit_info = JSON.parse(line) | ||
reused << unit_info["name"].as_s if unit_info["reused"].as_bool | ||
|
||
module_idx = unit_info["idx"].as_i | ||
slice.update(module_idx) do |unit| | ||
unit.compilation_time = unit_info["time"].as_f.seconds | ||
unit | ||
end | ||
|
||
@progress_tracker.stage_progress += 1 | ||
end | ||
end | ||
end | ||
|
||
codegen_process = Process.fork do | ||
pipe_w = pw | ||
slice.each do |unit| | ||
slice.each_with_index do |unit, idx| | ||
unit.compile | ||
if pipe_w | ||
unit_json = {name: unit.name, reused: unit.reused_previous_compilation?}.to_json | ||
unit_json = { | ||
name: unit.name, | ||
reused: unit.reused_previous_compilation?, | ||
idx: idx, | ||
time: unit.compilation_time.total_seconds, | ||
}.to_json | ||
pipe_w.puts unit_json | ||
end | ||
end | ||
|
@@ -547,6 +559,16 @@ module Crystal | |
puts " - #{unit.original_name} (#{unit.name}.bc)" | ||
end | ||
end | ||
|
||
if units.size != reused.size | ||
puts | ||
puts("Top 10 slowest modules:") | ||
units.sort_by! { |u| u.compilation_time * -1 } | ||
units.first(10).each do |unit| | ||
time_str = unit.compilation_time.to_s.ljust(18, ' ') | ||
z64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
puts " - #{unit.compilation_time} #{unit.original_name} (#{unit.name}.bc)" | ||
z64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
end | ||
|
||
getter(target_machine : LLVM::TargetMachine) do | ||
|
@@ -631,6 +653,7 @@ module Crystal | |
getter original_name | ||
getter llvm_mod | ||
getter? reused_previous_compilation = false | ||
property compilation_time : Time::Span = Time::Span::ZERO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be a |
||
@object_extension : String | ||
|
||
def initialize(@compiler : Compiler, program : Program, @name : String, | ||
|
@@ -661,7 +684,9 @@ module Crystal | |
end | ||
|
||
def compile | ||
compile_to_object | ||
@compilation_time = Time.measure do | ||
compile_to_object | ||
end | ||
end | ||
|
||
private def compile_to_object | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit
is a reference, so I believe direct mutation works and there is no need to do it like a value (unless there is some complication with forking)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pages in forked processes are copy-on-write by default. And the pages allocated by bdwgc are not marked as
MEM_SHARED
(probably for good reason, I'd wager). That is why this pipe mechanism is used, as a safe vehicle to share memory.Edit: Sorry, mistook the question; Yes - in this context we are in the parent thread, so mutating should be fine here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you still going to address this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HertzDevil No, make any changes you see fit.