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

binloginfo: Optimize addSpecialComment by reusing compiled regexp #10502

Conversation

Projects
None yet
4 participants
@suzaku
Copy link
Member

commented May 16, 2019

What problem does this PR solve?

Make addSpecialComment a little faster.

What is changed and how it works?

Reuse the compiled SHARD_ROW_ID_BITS regexp pattern to avoid compiling
it repeatedly.

Check List

Tests

  • Unit test

    The changed function is already covered in the test TestBinlog

Code changes

  • Has exported function/method change
    No
  • Has exported variable/fields change
    No
  • Has interface methods change
    No
  • Has persistent data change
    No

Side effects

  • Possible performance regression
    No, instead performance is improved, as can be verified in this
    benchmark.
  • Increased code complexity
    No.
  • Breaking backward compatibility
    No.

Related changes

  • Need to cherry-pick to the release branch
    No.
  • Need to update the documentation
    No.
  • Need to update the tidb-ansible repository
    No.
  • Need to be included in the release note
    No.
@CLAassistant

This comment has been minimized.

Copy link

commented May 16, 2019

CLA assistant check
All committers have signed the CLA.

@suzaku suzaku force-pushed the suzaku:reuse-compiled-regexp-and-avoid-unnecessary-ToUpper branch from 71040d0 to 78eb0eb May 16, 2019

@codecov

This comment has been minimized.

Copy link

commented May 16, 2019

Codecov Report

❗️ No coverage uploaded for pull request base (master@40ded29). Click here to learn what that means.
The diff coverage is 100%.

@@             Coverage Diff             @@
##             master     #10502   +/-   ##
===========================================
  Coverage          ?   78.3447%           
===========================================
  Files             ?        414           
  Lines             ?      87706           
  Branches          ?          0           
===========================================
  Hits              ?      68713           
  Misses            ?      13851           
  Partials          ?       5142

@XuHuaiyu XuHuaiyu requested a review from WangXiangUSTC May 24, 2019

loc := reg.FindStringIndex(upperQuery)
if len(loc) < 2 {
loc := shardPat.FindStringIndex(strings.ToUpper(ddlQuery))
if loc == nil {

This comment has been minimized.

Copy link
@WangXiangUSTC

WangXiangUSTC May 27, 2019

Member

why change the logic?

This comment has been minimized.

Copy link
@suzaku

suzaku May 27, 2019

Author Member

This is the documented way to check for "no match":

FindStringIndex returns a two-element slice of integers defining the location of the leftmost match in s of the regular expression. The match itself is at s[loc[0]:loc[1]]. A return value of nil indicates no match.

@WangXiangUSTC

This comment has been minimized.

Copy link
Member

commented May 29, 2019

LGTM

@zz-jason
Copy link
Member

left a comment

LGTM

@zz-jason zz-jason added status/LGT2 and removed status/LGT1 labels Jun 3, 2019

@zz-jason zz-jason merged commit 38e32f7 into pingcap:master Jun 4, 2019

8 checks passed

ci/circleci Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 0%)
Details
codecov/project No report found to compare against
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/build_check_race Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev_2 Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@suzaku suzaku deleted the suzaku:reuse-compiled-regexp-and-avoid-unnecessary-ToUpper branch Jun 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.