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

Use regex cache to save memory #33147

Merged
merged 171 commits into from
Aug 23, 2023
Merged

Use regex cache to save memory #33147

merged 171 commits into from
Aug 23, 2023

Conversation

YakDriver
Copy link
Member

@YakDriver YakDriver commented Aug 22, 2023

Description

Saves ~18% memory use by introducing a cache layer, regexache, between the code and regexp.MustCompile(). This de-duplicates regular expressions in memory. Althought regexache can expired cache entries, testing so far seems to show the greatest reduction in memory use when the cache is not cleaned up (no expiration).

To save memory, there may be a small performance hit from cache contention. This should be monitored to ensure it's not noticeable.

These are the results of profiling memory with and without regexache.

  • Not using regexache
    • Single VPC acc test: 6.76GB
    • 2 AppRunner acc tests: 17.89GB
  • Using regexache, no expiration
    • Single VPC acc test: 5.54GB (18% less than w/o)
    • 2 AppRunner acc tests: 14.81GB (17.2% less than w/o)
  • Using regexache, 1s expiration, expiration protection at 2 uses, 5s interval, 0.5s clean per interval
    • Single VPC acc test: 5.62GB (16.9% less than w/o)
    • 2 AppRunner acc tests: 15.00GB (16.2% less than w/o)
  • Using regexache, 0.5s expiration, expiration protection at 10 uses, 1s interval, 0.1s clean per interval
    • Single VPC acc test: 5.62GB (16.9% less than w/o)
    • 2 AppRunner acc tests: 15.01GB (16.1% less than w/o)
  • Using regexache, 2s expiration, expiration protection at 3 uses, 2s interval, 0.1s clean per interval
    • Single VPC acc test: 5.67GB (16.1% less than w/o)
    • 2 AppRunner acc tests: 15.05GB (15.9% less than w/o)

Relations

Relates #32289

References

Output from Acceptance Testing

% make sane
==> Sane Check (48 tests of Top 30 resources)
==> Like 'sanity' except full output and stops soon after 1st error
==> NOTE: NOT an exhaustive set of tests! Finds big problems only.
=== RUN   TestAccIAMInstanceProfile_basic
=== PAUSE TestAccIAMInstanceProfile_basic
=== RUN   TestAccIAMInstanceProfile_tags
=== PAUSE TestAccIAMInstanceProfile_tags
=== RUN   TestAccIAMPolicyDocumentDataSource_basic
=== PAUSE TestAccIAMPolicyDocumentDataSource_basic
=== RUN   TestAccIAMPolicyDocumentDataSource_sourceConflicting
=== PAUSE TestAccIAMPolicyDocumentDataSource_sourceConflicting
=== RUN   TestAccIAMPolicy_basic
=== PAUSE TestAccIAMPolicy_basic
=== RUN   TestAccIAMPolicy_tags
=== PAUSE TestAccIAMPolicy_tags
=== RUN   TestAccIAMPolicy_policy
=== PAUSE TestAccIAMPolicy_policy
=== RUN   TestAccIAMRolePolicyAttachment_basic
=== PAUSE TestAccIAMRolePolicyAttachment_basic
=== RUN   TestAccIAMRolePolicyAttachment_disappears
=== PAUSE TestAccIAMRolePolicyAttachment_disappears
=== RUN   TestAccIAMRolePolicyAttachment_Disappears_role
=== PAUSE TestAccIAMRolePolicyAttachment_Disappears_role
=== RUN   TestAccIAMRolePolicy_basic
=== PAUSE TestAccIAMRolePolicy_basic
=== RUN   TestAccIAMRolePolicy_unknownsInPolicy
=== PAUSE TestAccIAMRolePolicy_unknownsInPolicy
=== RUN   TestAccIAMRole_basic
=== PAUSE TestAccIAMRole_basic
=== RUN   TestAccIAMRole_namePrefix
=== PAUSE TestAccIAMRole_namePrefix
=== RUN   TestAccIAMRole_disappears
=== PAUSE TestAccIAMRole_disappears
=== RUN   TestAccIAMRole_InlinePolicy_basic
=== PAUSE TestAccIAMRole_InlinePolicy_basic
=== CONT  TestAccIAMInstanceProfile_basic
=== CONT  TestAccIAMRolePolicyAttachment_disappears
=== CONT  TestAccIAMRole_basic
=== CONT  TestAccIAMRolePolicy_unknownsInPolicy
=== CONT  TestAccIAMPolicy_basic
=== CONT  TestAccIAMRolePolicy_basic
=== CONT  TestAccIAMRolePolicyAttachment_basic
=== CONT  TestAccIAMRole_namePrefix
=== CONT  TestAccIAMRolePolicyAttachment_Disappears_role
=== CONT  TestAccIAMPolicyDocumentDataSource_basic
=== CONT  TestAccIAMInstanceProfile_tags
=== CONT  TestAccIAMRole_disappears
=== CONT  TestAccIAMPolicyDocumentDataSource_sourceConflicting
=== CONT  TestAccIAMPolicy_policy
=== CONT  TestAccIAMRole_InlinePolicy_basic
=== CONT  TestAccIAMPolicy_tags
--- PASS: TestAccIAMPolicyDocumentDataSource_sourceConflicting (71.17s)
--- PASS: TestAccIAMPolicyDocumentDataSource_basic (72.43s)
--- PASS: TestAccIAMRole_disappears (77.27s)
--- PASS: TestAccIAMRolePolicyAttachment_Disappears_role (80.29s)
--- PASS: TestAccIAMRolePolicyAttachment_disappears (81.18s)
--- PASS: TestAccIAMRolePolicy_unknownsInPolicy (83.53s)
--- PASS: TestAccIAMPolicy_basic (89.75s)
--- PASS: TestAccIAMRole_namePrefix (90.12s)
--- PASS: TestAccIAMRole_basic (90.87s)
--- PASS: TestAccIAMInstanceProfile_basic (91.17s)
--- PASS: TestAccIAMRolePolicy_basic (126.25s)
--- PASS: TestAccIAMRolePolicyAttachment_basic (127.09s)
--- PASS: TestAccIAMPolicy_policy (128.47s)
--- PASS: TestAccIAMPolicy_tags (157.70s)
--- PASS: TestAccIAMRole_InlinePolicy_basic (158.58s)
--- PASS: TestAccIAMInstanceProfile_tags (159.07s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/iam	161.478s
=== RUN   TestAccLogsGroup_basic
=== PAUSE TestAccLogsGroup_basic
=== RUN   TestAccLogsGroup_multiple
=== PAUSE TestAccLogsGroup_multiple
=== CONT  TestAccLogsGroup_basic
=== CONT  TestAccLogsGroup_multiple
--- PASS: TestAccLogsGroup_multiple (67.47s)
--- PASS: TestAccLogsGroup_basic (81.52s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/logs	84.429s
=== RUN   TestAccVPCDataSource_basic
=== PAUSE TestAccVPCDataSource_basic
=== RUN   TestAccVPCRouteTableAssociation_Subnet_basic
=== PAUSE TestAccVPCRouteTableAssociation_Subnet_basic
=== RUN   TestAccVPCRouteTable_basic
=== PAUSE TestAccVPCRouteTable_basic
=== RUN   TestAccVPCSecurityGroupRule_race
=== PAUSE TestAccVPCSecurityGroupRule_race
=== RUN   TestAccVPCSecurityGroupRule_protocolChange
=== PAUSE TestAccVPCSecurityGroupRule_protocolChange
=== RUN   TestAccVPCSecurityGroup_basic
=== PAUSE TestAccVPCSecurityGroup_basic
=== RUN   TestAccVPCSecurityGroup_ipRangesWithSameRules
=== PAUSE TestAccVPCSecurityGroup_ipRangesWithSameRules
=== RUN   TestAccVPCSecurityGroup_vpcAllEgress
=== PAUSE TestAccVPCSecurityGroup_vpcAllEgress
=== RUN   TestAccVPCSubnet_basic
=== PAUSE TestAccVPCSubnet_basic
=== RUN   TestAccVPC_tenancy
=== PAUSE TestAccVPC_tenancy
=== CONT  TestAccVPCDataSource_basic
=== CONT  TestAccVPCSecurityGroup_basic
=== CONT  TestAccVPCSecurityGroupRule_race
=== CONT  TestAccVPC_tenancy
=== CONT  TestAccVPCSecurityGroupRule_protocolChange
=== CONT  TestAccVPCSubnet_basic
=== CONT  TestAccVPCSecurityGroup_vpcAllEgress
=== CONT  TestAccVPCRouteTable_basic
=== CONT  TestAccVPCSecurityGroup_ipRangesWithSameRules
=== CONT  TestAccVPCRouteTableAssociation_Subnet_basic
--- PASS: TestAccVPCRouteTable_basic (102.50s)
--- PASS: TestAccVPCDataSource_basic (102.50s)
--- PASS: TestAccVPCSubnet_basic (102.66s)
--- PASS: TestAccVPCSecurityGroup_basic (104.06s)
--- PASS: TestAccVPCSecurityGroup_vpcAllEgress (104.53s)
--- PASS: TestAccVPCRouteTableAssociation_Subnet_basic (105.91s)
--- PASS: TestAccVPCSecurityGroup_ipRangesWithSameRules (106.86s)
--- PASS: TestAccVPCSecurityGroupRule_protocolChange (175.35s)
--- PASS: TestAccVPC_tenancy (176.35s)
--- PASS: TestAccVPCSecurityGroupRule_race (194.35s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	200.060s
=== RUN   TestAccECSService_basic
=== PAUSE TestAccECSService_basic
=== RUN   TestAccECSService_basicImport
=== PAUSE TestAccECSService_basicImport
=== RUN   TestAccECSTaskDefinition_basic
=== PAUSE TestAccECSTaskDefinition_basic
=== CONT  TestAccECSService_basic
=== CONT  TestAccECSTaskDefinition_basic
=== CONT  TestAccECSService_basicImport
--- PASS: TestAccECSTaskDefinition_basic (125.55s)
--- PASS: TestAccECSService_basic (176.12s)
--- PASS: TestAccECSService_basicImport (259.34s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ecs	262.046s
=== RUN   TestAccELBV2TargetGroup_basic
=== PAUSE TestAccELBV2TargetGroup_basic
=== CONT  TestAccELBV2TargetGroup_basic
--- PASS: TestAccELBV2TargetGroup_basic (73.80s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/elbv2	78.266s
=== RUN   TestAccKMSKey_basic
=== PAUSE TestAccKMSKey_basic
=== CONT  TestAccKMSKey_basic
--- PASS: TestAccKMSKey_basic (119.52s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/kms	125.110s
=== RUN   TestAccLambdaFunction_basic
=== PAUSE TestAccLambdaFunction_basic
=== RUN   TestAccLambdaPermission_basic
=== PAUSE TestAccLambdaPermission_basic
=== CONT  TestAccLambdaFunction_basic
=== CONT  TestAccLambdaPermission_basic
--- PASS: TestAccLambdaPermission_basic (101.96s)
--- PASS: TestAccLambdaFunction_basic (107.04s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/lambda	109.866s
=== RUN   TestAccMetaPartitionDataSource_basic
=== PAUSE TestAccMetaPartitionDataSource_basic
=== RUN   TestAccMetaRegionDataSource_basic
=== PAUSE TestAccMetaRegionDataSource_basic
=== RUN   TestAccMetaRegionDataSource_endpoint
=== PAUSE TestAccMetaRegionDataSource_endpoint
=== RUN   TestAccMetaRegionDataSource_endpointAndName
=== PAUSE TestAccMetaRegionDataSource_endpointAndName
=== CONT  TestAccMetaPartitionDataSource_basic
=== CONT  TestAccMetaRegionDataSource_endpoint
=== CONT  TestAccMetaRegionDataSource_endpointAndName
=== CONT  TestAccMetaRegionDataSource_basic
--- PASS: TestAccMetaRegionDataSource_basic (69.50s)
--- PASS: TestAccMetaPartitionDataSource_basic (70.56s)
--- PASS: TestAccMetaRegionDataSource_endpoint (71.75s)
--- PASS: TestAccMetaRegionDataSource_endpointAndName (71.98s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/meta	76.843s
=== RUN   TestAccRoute53Record_basic
=== PAUSE TestAccRoute53Record_basic
=== RUN   TestAccRoute53Record_Latency_basic
=== PAUSE TestAccRoute53Record_Latency_basic
=== RUN   TestAccRoute53ZoneDataSource_name
=== PAUSE TestAccRoute53ZoneDataSource_name
=== CONT  TestAccRoute53Record_basic
=== CONT  TestAccRoute53ZoneDataSource_name
=== CONT  TestAccRoute53Record_Latency_basic
--- PASS: TestAccRoute53ZoneDataSource_name (111.54s)
--- PASS: TestAccRoute53Record_basic (167.45s)
--- PASS: TestAccRoute53Record_Latency_basic (188.90s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/route53	194.273s
=== RUN   TestAccS3BucketACL_updateACL
=== PAUSE TestAccS3BucketACL_updateACL
=== RUN   TestAccS3BucketPolicy_basic
=== PAUSE TestAccS3BucketPolicy_basic
=== RUN   TestAccS3BucketPublicAccessBlock_basic
=== PAUSE TestAccS3BucketPublicAccessBlock_basic
=== RUN   TestAccS3Bucket_Basic_basic
=== PAUSE TestAccS3Bucket_Basic_basic
=== RUN   TestAccS3Bucket_Security_corsUpdate
=== PAUSE TestAccS3Bucket_Security_corsUpdate
=== CONT  TestAccS3BucketACL_updateACL
=== CONT  TestAccS3Bucket_Basic_basic
=== CONT  TestAccS3BucketPublicAccessBlock_basic
=== CONT  TestAccS3Bucket_Security_corsUpdate
=== CONT  TestAccS3BucketPolicy_basic
--- PASS: TestAccS3Bucket_Basic_basic (94.10s)
--- PASS: TestAccS3BucketPolicy_basic (95.13s)
--- PASS: TestAccS3BucketPublicAccessBlock_basic (95.26s)
--- PASS: TestAccS3BucketACL_updateACL (134.71s)
--- PASS: TestAccS3Bucket_Security_corsUpdate (134.95s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/s3	139.151s
=== RUN   TestAccSecretsManagerSecret_basic
=== PAUSE TestAccSecretsManagerSecret_basic
=== RUN   TestAccSecretsManagerSecret_basicReplica
=== PAUSE TestAccSecretsManagerSecret_basicReplica
=== CONT  TestAccSecretsManagerSecret_basic
=== CONT  TestAccSecretsManagerSecret_basicReplica
--- PASS: TestAccSecretsManagerSecret_basic (81.41s)
--- PASS: TestAccSecretsManagerSecret_basicReplica (106.01s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/secretsmanager	111.525s
=== RUN   TestAccSTSCallerIdentityDataSource_basic
=== PAUSE TestAccSTSCallerIdentityDataSource_basic
=== CONT  TestAccSTSCallerIdentityDataSource_basic
--- PASS: TestAccSTSCallerIdentityDataSource_basic (61.62s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/sts	67.149s

@github-actions github-actions bot added service/grafana Issues and PRs that pertain to the grafana service. service/appintegrations Issues and PRs that pertain to the appintegrations service. service/ds Issues and PRs that pertain to the ds service. service/ce Issues and PRs that pertain to the ce service. service/deploy Issues and PRs that pertain to the deploy service. service/appautoscaling Issues and PRs that pertain to the appautoscaling service. service/cognitoidp Issues and PRs that pertain to the cognitoidp service. service/dms Issues and PRs that pertain to the dms service. service/cognitoidentity Issues and PRs that pertain to the cognitoidentity service. service/ec2outposts Issues and PRs that pertain to the ec2outposts service. service/cloudcontrol Issues and PRs that pertain to the cloudcontrol service. service/cur Issues and PRs that pertain to the cur service. service/evidently Issues and PRs that pertain to the evidently service. service/ec2ebs Issues and PRs that pertain to the ec2ebs service. service/fis Issues and PRs that pertain to the fis service. service/emrserverless Issues and PRs that pertain to the emrserverless service. service/chimesdkmediapipelines Issues and PRs that pertain to the chimesdkmediapipelines service. service/chimesdkvoice Issues and PRs that pertain to the chimesdkvoice service. service/cleanrooms Issues and PRs that pertain to the cleanrooms service. service/internetmonitor Issues and PRs that pertain to the internetmonitor service. labels Aug 22, 2023
@YakDriver YakDriver merged commit 15f4b87 into main Aug 23, 2023
@YakDriver YakDriver deleted the f-mem-regex-save branch August 23, 2023 13:46
@github-actions github-actions bot added this to the v5.14.0 milestone Aug 23, 2023
@github-actions
Copy link

This functionality has been released in v5.14.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
create Pertains to generating names, hashcodes, etc. generators Relates to code generators. provider Pertains to the provider itself, rather than any interaction with AWS. service/accessanalyzer Issues and PRs that pertain to the accessanalyzer service. service/account Issues and PRs that pertain to the account service. service/acm Issues and PRs that pertain to the acm service. service/acmpca Issues and PRs that pertain to the acmpca service. service/amplify Issues and PRs that pertain to the amplify service. service/apigateway Issues and PRs that pertain to the apigateway service. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service. service/appautoscaling Issues and PRs that pertain to the appautoscaling service. service/appconfig Issues and PRs that pertain to the appconfig service. service/appflow Issues and PRs that pertain to the appflow service. service/appintegrations Issues and PRs that pertain to the appintegrations service. service/appmesh Issues and PRs that pertain to the appmesh service. service/apprunner Issues and PRs that pertain to the apprunner service. service/appsync Issues and PRs that pertain to the appsync service. service/athena Issues and PRs that pertain to the athena service. service/auditmanager Issues and PRs that pertain to the auditmanager service. service/autoscaling Issues and PRs that pertain to the autoscaling service. service/autoscalingplans Issues and PRs that pertain to the autoscalingplans service. service/backup Issues and PRs that pertain to the backup service. service/batch Issues and PRs that pertain to the batch service. service/budgets Issues and PRs that pertain to the budgets service. service/ce Issues and PRs that pertain to the ce service. service/chime Issues and PRs that pertain to the chime service. service/chimesdkmediapipelines Issues and PRs that pertain to the chimesdkmediapipelines service. service/chimesdkvoice Issues and PRs that pertain to the chimesdkvoice service. service/cleanrooms Issues and PRs that pertain to the cleanrooms service. service/cloud9 Issues and PRs that pertain to the cloud9 service. service/cloudcontrol Issues and PRs that pertain to the cloudcontrol service. service/cloudformation Issues and PRs that pertain to the cloudformation service. service/cloudfront Issues and PRs that pertain to the cloudfront service. service/cloudhsmv2 Issues and PRs that pertain to the cloudhsmv2 service. service/cloudsearch Issues and PRs that pertain to the cloudsearch service. service/cloudtrail Issues and PRs that pertain to the cloudtrail service. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/codeartifact Issues and PRs that pertain to the codeartifact service. service/codebuild Issues and PRs that pertain to the codebuild service. service/codecommit Issues and PRs that pertain to the codecommit service. service/codegurureviewer Issues and PRs that pertain to the codegurureviewer service. service/codepipeline Issues and PRs that pertain to the codepipeline service. service/codestarconnections Issues and PRs that pertain to the codestarconnections service. service/codestarnotifications Issues and PRs that pertain to the codestarnotifications service. service/cognitoidentity Issues and PRs that pertain to the cognitoidentity service. service/cognitoidp Issues and PRs that pertain to the cognitoidp service. service/comprehend Issues and PRs that pertain to the comprehend service. service/configservice Issues and PRs that pertain to the configservice service. service/connect Issues and PRs that pertain to the connect service. service/cur Issues and PRs that pertain to the cur service. service/dataexchange Issues and PRs that pertain to the dataexchange service. service/datasync Issues and PRs that pertain to the datasync service. service/dax Issues and PRs that pertain to the dax service. service/deploy Issues and PRs that pertain to the deploy service. service/devicefarm Issues and PRs that pertain to the devicefarm service. service/directconnect Issues and PRs that pertain to the directconnect service. service/dlm Issues and PRs that pertain to the dlm service. service/dms Issues and PRs that pertain to the dms service. service/docdb Issues and PRs that pertain to the docdb service. service/ds Issues and PRs that pertain to the ds service. service/dynamodb Issues and PRs that pertain to the dynamodb service. service/ec2ebs Issues and PRs that pertain to the ec2ebs service. service/ec2outposts Issues and PRs that pertain to the ec2outposts service. service/ec2 Issues and PRs that pertain to the ec2 service. service/ecr Issues and PRs that pertain to the ecr service. service/ecrpublic Issues and PRs that pertain to the ecrpublic service. service/ecs Issues and PRs that pertain to the ecs service. service/efs Issues and PRs that pertain to the efs service. service/eks Issues and PRs that pertain to the eks service. service/elasticache Issues and PRs that pertain to the elasticache service. service/elasticbeanstalk Issues and PRs that pertain to the elasticbeanstalk service. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. service/elastictranscoder Issues and PRs that pertain to the elastictranscoder service. service/elb Issues and PRs that pertain to the elb service. service/elbv2 Issues and PRs that pertain to the elbv2 service. service/emr Issues and PRs that pertain to the emr service. service/emrcontainers Issues and PRs that pertain to the emrcontainers service. service/emrserverless Issues and PRs that pertain to the emrserverless service. service/events Issues and PRs that pertain to the events service. service/evidently Issues and PRs that pertain to the evidently service. service/firehose Issues and PRs that pertain to the firehose service. service/fis Issues and PRs that pertain to the fis service. service/fms Issues and PRs that pertain to the fms service. service/fsx Issues and PRs that pertain to the fsx service. service/gamelift Issues and PRs that pertain to the gamelift service. service/glacier Issues and PRs that pertain to the glacier service. service/globalaccelerator Issues and PRs that pertain to the globalaccelerator service. service/glue Issues and PRs that pertain to the glue service. service/grafana Issues and PRs that pertain to the grafana service. service/guardduty Issues and PRs that pertain to the guardduty service. service/iam Issues and PRs that pertain to the iam service. service/identitystore Issues and PRs that pertain to the identitystore service. service/imagebuilder Issues and PRs that pertain to the imagebuilder service. service/inspector Issues and PRs that pertain to the inspector service. service/internetmonitor Issues and PRs that pertain to the internetmonitor service. size/XL Managed by automation to categorize the size of a PR. sweeper Pertains to changes to or issues with the sweeper. tags Pertains to resource tagging. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. verify Pertains to the verify package (i.e., provider-level validating, diff suppression, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant