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

fix: use path.Join replace fmt.Sprintf to set the path value #3163

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

WillardHu
Copy link
Collaborator

Signed-off-by: WillardHu wei.hu@daocloud.io

What type of PR is this?

/kind bug

What this PR does / why we need it:

Better performance and readability

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Signed-off-by: WillardHu <wei.hu@daocloud.io>
@kubeedge-bot kubeedge-bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 10, 2021
@kubeedge-bot kubeedge-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 10, 2021
@@ -60,20 +61,20 @@ func (factory *eventbusFactory) GetSource(ep *v1.RuleEndpoint, sourceResource ma
}

func (eb *EventBus) RegisterListener(handle listener.Handle) error {
listener.MessageHandlerInstance.AddListener(fmt.Sprintf("%s/node/%s/%s/%s", "bus", eb.nodeName, eb.namespace, eb.subTopic), handle)
listener.MessageHandlerInstance.AddListener(path.Join("bus/node", eb.nodeName, eb.namespace, eb.subTopic), handle)
Copy link
Member

Choose a reason for hiding this comment

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

can you pls share some data on how the performance got improved?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

var s1t time.Time
var used time.Duration

s1t = time.Now()
for i := 0; i < 100000; i++ {
    fmt.Sprintf("node/%s/%s/%s", "nodeName", "namespace", "subTopic")
}
used = time.Since(s1t)
fmt.Println("time cost of `sprintf`:", used)

s1t = time.Now()
for i := 0; i < 100000; i++ {
    path.Join("node", "nodeName", "namespace", "subTopic")
}
used = time.Since(s1t)
fmt.Println("time cost of `join`:", used)

Run 3 times pirnt out:

=== RUN   TestPathJoin
time cost of `sprintf`: 15.840042ms
time cost of `join`: 12.771455ms
--- PASS: TestPathJoin (0.03s)

=== RUN   TestPathJoin
time cost of `sprintf`: 14.852592ms
time cost of `join`: 12.130716ms
--- PASS: TestPathJoin (0.03s)

=== RUN   TestPathJoin
time cost of `sprintf`: 19.307545ms
time cost of `join`: 14.843423ms
--- PASS: TestPathJoin (0.03s)

@zc2638
Copy link
Member

zc2638 commented Sep 10, 2021

/lgtm

@kubeedge-bot kubeedge-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 10, 2021
Copy link
Member

@fisherxu fisherxu left a comment

Choose a reason for hiding this comment

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

/approve

@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fisherxu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 14, 2021
@kubeedge-bot kubeedge-bot merged commit c6269a0 into kubeedge:master Sep 14, 2021
@WillardHu WillardHu deleted the fix/pathjoin branch September 15, 2021 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants