开发者

java JIT -- what optimizations are possible?

开发者 https://www.devze.com 2023-02-09 15:30 出处:网络
Academically curious. Can the JIT take code like this, recognize that the format string is static final and thus precompute the sliced format string, thus optimizing this down to only StringBuilder wi

Academically curious. Can the JIT take code like this, recognize that the format string is static final and thus precompute the sliced format string, thus optimizing this down to only StringBuilder with minimal appends?

public static String buildDeleteSql(BaseObject object)
{
    String table;
    String schema;

    String deleteSql = String.format(
            "DELETE FROM %s.%s WHERE %s = '%s' AND %s = '%s开发者_Go百科'",
            schema,
            table,
            BaseObject.ATTR_ID,
            StringUtils.escapeForSQLString(object.getId()),
            BaseObject.ATTR_REVISION,
            StringUtils.escapeForSQLString(object.getRevision())
        );

    return deleteSql;
}


Theoretically, a JVM could probably grok your example. Meantime, in reality, existing JVMs won't; it's probably not a very lucrative place to spend the budget for optimizations. Especially since string formatting is usually done to serialize data, in which case you'll probably end up spending most of the time waiting for I/O to complete.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号