Skip to content

Commit b363a5c

Browse files
committed
Reapply "Reduce initial memory usage by auto-loading bundled gems (2) (#3088)"
This reverts commit 9d284b6.
1 parent b39fe53 commit b363a5c

File tree

9 files changed

+41
-15
lines changed

9 files changed

+41
-15
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Reduce initial memory usage by auto-loading bundled gems (STS, SSO, SSOOIDC).
5+
46
3.201.5 (2024-08-15)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,7 @@
109109
# defaults
110110
require_relative 'aws-defaults'
111111

112-
# plugins
113-
# loaded through building STS or SSO ..
114-
115-
# aws-sdk-sts is included to support Aws::AssumeRoleCredentials
116-
require_relative 'aws-sdk-sts'
117-
118-
# aws-sdk-sso is included to support Aws::SSOCredentials
119-
require_relative 'aws-sdk-sso'
120-
require_relative 'aws-sdk-ssooidc'
112+
# plugins - loaded through service clients as needed.
121113

122114
module Aws
123115

@@ -205,3 +197,14 @@ def eager_autoload!(*args)
205197

206198
end
207199
end
200+
201+
# Autoload bundled service gems used in credential providers
202+
# need to ensure that the files are the local files from aws-sdk-core
203+
# and not the installed, legacy/dummy service gems.
204+
205+
# aws-sdk-sts is included to support Aws::AssumeRoleCredentials
206+
Aws.autoload :STS, File.join(__dir__, 'aws-sdk-sts.rb')
207+
208+
# aws-sdk-sso is included to support Aws::SSOCredentials
209+
Aws.autoload :SSO, File.join(__dir__, 'aws-sdk-sso.rb')
210+
Aws.autoload :SSOOIDC, File.join(__dir__, 'aws-sdk-ssooidc.rb')

gems/aws-sdk-core/lib/aws-sdk-sso.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
#
88
# WARNING ABOUT GENERATED CODE
99

10-
1110
unless Module.const_defined?(:Aws)
1211
require 'aws-sdk-core'
1312
require 'aws-sigv4'
1413
end
1514

15+
if Aws.autoload?(:SSO) &&
16+
!(defined?(JRUBY_VERSION) && JRUBY_VERSION < '9.3')
17+
Aws.autoload(:SSO, __FILE__)
18+
end
19+
1620
require_relative 'aws-sdk-sso/types'
1721
require_relative 'aws-sdk-sso/client_api'
1822
require_relative 'aws-sdk-sso/plugins/endpoints.rb'

gems/aws-sdk-core/lib/aws-sdk-ssooidc.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
#
88
# WARNING ABOUT GENERATED CODE
99

10-
1110
unless Module.const_defined?(:Aws)
1211
require 'aws-sdk-core'
1312
require 'aws-sigv4'
1413
end
1514

15+
if Aws.autoload?(:SSOOIDC) &&
16+
!(defined?(JRUBY_VERSION) && JRUBY_VERSION < '9.3')
17+
Aws.autoload(:SSOOIDC, __FILE__)
18+
end
19+
1620
require_relative 'aws-sdk-ssooidc/types'
1721
require_relative 'aws-sdk-ssooidc/client_api'
1822
require_relative 'aws-sdk-ssooidc/plugins/endpoints.rb'

gems/aws-sdk-core/lib/aws-sdk-sts.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
#
88
# WARNING ABOUT GENERATED CODE
99

10-
1110
unless Module.const_defined?(:Aws)
1211
require 'aws-sdk-core'
1312
require 'aws-sigv4'
1413
end
1514

15+
if Aws.autoload?(:STS) &&
16+
!(defined?(JRUBY_VERSION) && JRUBY_VERSION < '9.3')
17+
Aws.autoload(:STS, __FILE__)
18+
end
19+
1620
require_relative 'aws-sdk-sts/types'
1721
require_relative 'aws-sdk-sts/client_api'
1822
require_relative 'aws-sdk-sts/plugins/endpoints.rb'

gems/aws-sdk-resources/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Remove autoloads for service gems bundled in `aws-sdk-core` (STS, SSO, SSOOIDC).
5+
46
3.201.0 (2024-08-12)
57
------------------
68

gems/aws-sdk-resources/bin/aws-v3.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ def env_bool key, default
106106
# The Aws namespace used to check autoload requires aws-sdk-resources.
107107
require 'aws-sdk-resources'
108108

109-
# Finally load all of the gems. Core is loaded a second time because of STS.
109+
# Finally load all of the gems.
110+
# Don't update the load path for gems bundled in core.
111+
core_gems = [:STS, :SSO, :SSOOIDC]
110112
if File.directory?(File.expand_path('../../../../build_tools', __FILE__))
111113
gems = []
112114
Aws.constants.each do |const_name|
113-
if Aws.autoload?(const_name)
115+
if Aws.autoload?(const_name) && !core_gems.include?(const_name)
114116
gems << "aws-sdk-#{const_name.downcase}"
115117
end
116118
end

tasks/build.rake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ end
2828
# It is need to provide session credentials and assume role support.
2929
# Only building source, but not gemspecs, version file, etc.
3030
task 'build:aws-sdk-sts' do
31+
Aws::STS if Aws.autoload?(:STS) # force autoload from core
3132
sts = BuildTools::Services.service('sts')
3233
generator = AwsSdkCodeGenerator::CodeBuilder.new(
3334
aws_sdk_core_lib_path: $CORE_LIB,
@@ -48,6 +49,7 @@ end
4849
# It is need to provide SSO Credentials.
4950
# Only building source, but not gemspecs, version file, etc.
5051
task 'build:aws-sdk-sso' do
52+
Aws::SSO if Aws.autoload?(:SSO) # force autoload from core
5153
sso = BuildTools::Services.service('sso')
5254
generator = AwsSdkCodeGenerator::CodeBuilder.new(
5355
aws_sdk_core_lib_path: $CORE_LIB,
@@ -66,6 +68,7 @@ end
6668
# Aws::SSOOIDC is generated directly into the `aws-sdk-core` gem.
6769
# Only building source, but not gemspecs, version file, etc.
6870
task 'build:aws-sdk-ssooidc' do
71+
Aws::SSOOIDC if Aws.autoload?(:SSOOIDC) # force autoload from core
6972
ssooidc = BuildTools::Services.service('ssooidc')
7073
generator = AwsSdkCodeGenerator::CodeBuilder.new(
7174
aws_sdk_core_lib_path: $CORE_LIB,

tasks/update-aws-sdk-dependencies.rake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ task 'update-aws-sdk-dependencies' do
1919
)
2020

2121
# update the module autoloads
22+
# Remove service gems bundled in core (eg, sts) that have gem_name of aws-sdk-core.
23+
autoload_services = BuildTools::Services.select { |svc| svc.gem_name != 'aws-sdk-core' }
2224
BuildTools.replace_lines(
2325
filename: "#{$GEMS_DIR}/aws-sdk-resources/lib/aws-sdk-resources.rb",
2426
start: /# service gems/,
2527
stop: /# end service gems/,
26-
new_lines: BuildTools::Services.map { |service|
28+
new_lines: autoload_services.map { |service|
2729
" autoload :#{service.name}, '#{service.gem_name}'\n"
2830
}
2931
)

0 commit comments

Comments
 (0)