You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Beata Sudi (Jira)" <ji...@apache.org> on 2019/12/09 12:52:00 UTC
[jira] [Commented] (HBASE-17512) Optimize ServerName.parsePort() to
reduce objects creation
[ https://issues.apache.org/jira/browse/HBASE-17512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16991556#comment-16991556 ]
Beata Sudi commented on HBASE-17512:
------------------------------------
Hi!
[~samglover] are you still working on this issue? If not, I could finish it.
And it seems like parsePort(), parseStartcode() and parseHostname() has been marked deprecated since 2.0, but still being used in BackupUtils.
> Optimize ServerName.parsePort() to reduce objects creation
> ----------------------------------------------------------
>
> Key: HBASE-17512
> URL: https://issues.apache.org/jira/browse/HBASE-17512
> Project: HBase
> Issue Type: Bug
> Affects Versions: 1.2.4
> Reporter: Jean-Marc Spaggiari
> Assignee: Samuel David Glover
> Priority: Minor
> Labels: beginner
>
> ServerName.parsePort() calls the split method on a string. This string format is like "www.example.org,1234,1212121212" where we try to get only 1234. Each time the split() method is called, it creates 4 objets. 3 strings and an array. And we just us one of those strings.
> This this method is called in a single place. In the constructor:
> {code}
> private ServerName(final String serverName) {
> this(parseHostname(serverName), parsePort(serverName),
> parseStartcode(serverName));
> }
> {code}
> So parsePort creates 3 string. Te hostname, the port, the startcode, but returns only the port, while we call 2 other methods to redo the exact same work.
> This constructor is called only there:
> {code}
> /**
> * Retrieve an instance of ServerName.
> * Callers should use the equals method to compare returned instances, though we may return
> * a shared immutable object as an internal optimization.
> */
> public static ServerName valueOf(final String serverName) {
> return new ServerName(serverName);
> }
> {code}
> and this is called here and there. Not intensively, but still, should be cleaned.
> Instead of using split, something like this might do better:
> {code}
> public static int parsePort(final String serverName) {
> int indexStart = serverName.indexOf(SERVERNAME_SEPARATOR);
> int indexStop = serverName.lastIndexOf(SERVERNAME_SEPARATOR);
> return Integer.parseInt(serverName.substring(indexStart + 1, indexStop));
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)