简体   繁体   English

java JIT - 可以进行哪些优化?

[英]java JIT — what optimizations are possible?

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? JIT可以采用这样的代码,认识到格式字符串是静态最终的,因此预先计算切片格式字符串,从而将其优化为只有StringBuilder并且附加次数最少吗?

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

    String deleteSql = String.format(
            "DELETE FROM %s.%s WHERE %s = '%s' AND %s = '%s'",
            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. 从理论上讲,JVM可能会让你感觉很好。 Meantime, in reality, existing JVMs won't; 实际上,现有的JVM不会; 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. 特别是因为字符串格式化通常用于序列化数据,在这种情况下,您可能最终会花费大部分时间等待I / O完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM