Skip to content

kvm: remove unnecessary new String#4870

Merged
yadvr merged 2 commits into
apache:4.15from
ustcweizhou:4.15-kvm-remove-new-string
Apr 4, 2021
Merged

kvm: remove unnecessary new String#4870
yadvr merged 2 commits into
apache:4.15from
ustcweizhou:4.15-kvm-remove-new-string

Conversation

@ustcweizhou

Copy link
Copy Markdown
Contributor

Description

Thanks @rubieHess to point it out.
see #4800 (comment)

I detect that this code is problematic. According to the Performance (PERFORMANCE), Dm: Method invokes inefficient new String(String) constructor (DM_STRING_CTOR).
Using the java.lang.String(String) constructor wastes memory because the object so constructed will be functionally indistinguishable from the String passed as a parameter.  Just use the argument String directly.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

@GabrielBrascher GabrielBrascher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, @ustcweizhou. I am +1 on removing the String constructors, they should be avoided indeed.

I would also suggest externalizing them to constants, what do you think?

In terms of performance, I think that it does not change much being a constant or not. The way you are doing the String object is created only once. Java will detect the duplicated Strings in runtime and reuse them from the String's constant pool.

However, constants help code maintainability and readability. Especially on the duplicated Strings where a developer can easily change all occurrences by simply altering the constant.

@weizhouapache

Copy link
Copy Markdown
Member

Thanks for this PR, @ustcweizhou. I am +1 on removing the String constructors, they should be avoided indeed.

I would also suggest externalizing them to constants, what do you think?

In terms of performance, I think that it does not change much being a constant or not. The way you are doing the String object is created only once. Java will detect the duplicated Strings in runtime and reuse them from the String's constant pool.

However, constants help code maintainability and readability. Especially on the duplicated Strings where a developer can easily change all occurrences by simply altering the constant.

@GabrielBrascher
agree. I will update this pr.

@DaanHoogland DaanHoogland added this to the 4.15.1.0 milestone Mar 29, 2021
@yadvr

yadvr commented Mar 29, 2021

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✔️ centos8 ✖️ debian. SL-JID 280

@yadvr

yadvr commented Mar 29, 2021

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-285)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 46496 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4870-t285-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_affinity_groups_projects.py
Intermittent failure detected: /marvin/tests/smoke/test_affinity_groups.py
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_privategw_acl.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_router_nics.py
Intermittent failure detected: /marvin/tests/smoke/test_hostha_kvm.py
Smoke tests completed. 81 look OK, 5 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_DeployVmAntiAffinityGroup_in_project Error 63.57 test_affinity_groups_projects.py
test_DeployVmAntiAffinityGroup Error 41.98 test_affinity_groups.py
test_04_deploy_and_scale_kubernetes_cluster Failure 23.21 test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
test_08_deploy_and_upgrade_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardown Error 60.13 test_kubernetes_clusters.py
test_04_rvpc_network_garbage_collector_nics Failure 326.07 test_vpc_redundant.py
test_hostha_kvm_host_degraded Failure 677.61 test_hostha_kvm.py
test_hostha_kvm_host_fencing Failure 642.08 test_hostha_kvm.py
test_hostha_kvm_host_recovering Failure 643.95 test_hostha_kvm.py

@DaanHoogland

Copy link
Copy Markdown
Contributor

pl wait with merging @rhtyd , I think @weizhouapache wants to externalise those strings to constants as well.

@Pearl1594

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✖️ centos8 ✔️ debian. SL-JID 295

@GabrielBrascher GabrielBrascher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, @ustcweizhou.
Code LGTM.

@yadvr

yadvr commented Apr 1, 2021

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-324)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 40567 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4870-t324-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Smoke tests completed. 84 look OK, 2 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestKubernetesCluster>:teardown Error 69.81 test_kubernetes_clusters.py
test_01_migrate_VM_and_root_volume Error 69.20 test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disks Error 49.03 test_vm_life_cycle.py

@DaanHoogland

Copy link
Copy Markdown
Contributor

great work once a gain @weizhouapache. ok to merge @rhtyd / @shwstppr ?

@yadvr yadvr merged commit 0942838 into apache:4.15 Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants