Remove unused files upon gem install#6
Conversation
|
|
||
| dir = Datadog::RubyCoreSource.deduce_packaged_source_dir("ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}") | ||
|
|
||
| unused = Dir.glob(File.dirname(dir) + '/*') - [dir] |
There was a problem hiding this comment.
⚪ Code Quality Violation
Consider using string interpolation or formatting instead of concatenation. (...read more)
The rule "Avoid string concatenation" is an important coding practice in Ruby for ensuring efficient and clean code. String concatenation in Ruby using the '+' operator creates a new string object, which can lead to excessive memory usage and slower performance when dealing with large strings or performing the operation multiple times.
Instead, Ruby provides alternatives that are more efficient. The string interpolation syntax #{} allows you to insert variables directly into strings without creating new string objects. This is not only more memory efficient, but also provides cleaner and more readable code.
Another alternative is the format method, which allows you to create a formatted string with placeholders for variables. This method is particularly useful when dealing with more complex strings, as it provides a clear and concise way to format your strings.
By following this rule, you can write more efficient and cleaner Ruby code, leading to better performance and readability.
| require 'mkmf' | ||
| require 'fileutils' | ||
|
|
||
| $LOAD_PATH.push(__dir__ + '/../../lib') |
There was a problem hiding this comment.
⚪ Code Quality Violation
Consider using string interpolation or formatting instead of concatenation. (...read more)
The rule "Avoid string concatenation" is an important coding practice in Ruby for ensuring efficient and clean code. String concatenation in Ruby using the '+' operator creates a new string object, which can lead to excessive memory usage and slower performance when dealing with large strings or performing the operation multiple times.
Instead, Ruby provides alternatives that are more efficient. The string interpolation syntax #{} allows you to insert variables directly into strings without creating new string objects. This is not only more memory efficient, but also provides cleaner and more readable code.
Another alternative is the format method, which allows you to create a formatted string with placeholders for variables. This method is particularly useful when dealing with more complex strings, as it provides a clear and concise way to format your strings.
By following this rule, you can write more efficient and cleaner Ruby code, leading to better performance and readability.
|
|
||
| require 'datadog/ruby_core_source' | ||
|
|
||
| dir = Datadog::RubyCoreSource.deduce_packaged_source_dir("ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}") |
There was a problem hiding this comment.
PROBABLY we should move this whole bit of logic here in as well:
datadog-ruby_core_source/lib/datadog/ruby_core_source.rb
Lines 20 to 24 in 4b3cc1c
There was a problem hiding this comment.
Also, maybe for 3.4 preview we might need to add stuff in here?
datadog-ruby_core_source/lib/datadog/ruby_core_source.rb
Lines 6 to 11 in 4b3cc1c
There was a problem hiding this comment.
I think we need documentation somewhere on why this empty file exists.
Can we add a comment in it? Or maybe in the ext/shave/extconf.rb above?
There was a problem hiding this comment.
Sure, I just threw this 5min hackjob out to see if the idea held water.
|
@ivoanjo found the idea dangerous in face of weird stuff users may be creatively doing. Here's the scenario laid out:
As is, this could be fixed by Note that:
The issue could be addressed by packaging all patch versions for a given minor version instead of only the one matching, a case that was considered as a requirement (e.g 2.5.x, 3.3.0 and 3.3.5, 3.4.0-preview1 and 3.4.0-preview2) but not yet implemented in order to gather quick feedback with a minimal, early implementation. Since Ivo remained unconvinced that this could be reliably addressed and this is ultimately solely profiling depending on this gem's behaviour as of today, I am closing this. |
Given that:
RubyCoreSource.create_makefile_with_coreis the main entry point and computes things from the current runtime informationRubyCoreSource.deduce_packaged_source_dirreceives that informationLet's directly make use of that to reduce the gem size post-install
by adding a scri...Wait, not post-install. That's too manual. Let's do it zero-step, at install time.
extconf.rbis just a ruby script.spec.extensions = ['path/to/some/script.rb']is but a callback mechanism to call the above script.ext/foo/extconf.rbis a mere convention.Buuuuut it has to have a
Makefile(also convention because hey, it's namedextensionafter all)... so let's add a dummyMakeMakefile.create_makefilewith an empty, unused stub C file.Results:
Yup. 1.6 MB, down from
master's 8-ish MB.Note: I tried to use
MakeMakefile.dummy_makefilebut it failed so I resorted to the above as a quick hack. Should not be that hard to create aMakefilethat does nothing instead?