Repository navigation
rgw/dbstore: use string_view for string constants - #45109
Conversation
Signed-off-by: Casey Bodley <[email protected]>
f175467 to
efad4cc
Compare
|
added a couple extra commits, one addressing this part:
|
f8faf99 to
6839b5f
Compare
Signed-off-by: Casey Bodley <[email protected]>
these functions only refer to static member variables, so can be static themselves Signed-off-by: Casey Bodley <[email protected]>
all string constants passed to sqlite3_bind_parameter_index() are now `static constexpr const char*` instead of `std::string` Signed-off-by: Casey Bodley <[email protected]>
in `SQLiteDB::InitPrepareParams()`, `DBOpInfo::query_str` is assigned to `DBOpPrepareInfo::query_str`: p_params.op.query_str = params->op.query_str; by making `DBOpPrepareInfo::query_str` a view, we avoid allocating a copy of the `std::string` Signed-off-by: Casey Bodley <[email protected]>
6839b5f to
146a926
Compare
|
@soumyakoduri do you think this needs a teuthology run? the unit tests are passing in 'make check', and i confirmed that the packages built successfully in https://shaman.ceph.com/builds/ceph/wip-rgw-dbstore-strings/ |
Thats seems enough. Anyways there are no teuthology tests added for DBStore yet. I think this PR can be merged. |
taking this example:
here, the string literal
"DELETE from ..."gets stored in the data segment of the executable. but each time aRemoveUserOpis constructed, thestd::stringhas to allocate memory and make a copy of that string literalmaking this a
static const std::stringis a slight improvement, because this allocation/copy only happens once when the process starts up. but when there are a lot of these static strings, it takes time to initialize them all. and because this is linked into radosgw/radosgw-admin, it would initialize them even when we aren't using dbstorewhat we really want is a pointer directly to the string literal. so either a raw pointer:
or a
std::string_view, which is a pointer and length:there are several tradeoffs to consider here. the biggest one is that
std::string_view(as a pointer+length) does not represent a null-terminated string, so has noc_str()function for use with c APIs that takeconst char*. that means it's mostly for use in pure c++in this PR, i've only replaced the constant
std::strings that are passed tofmt::format(), which understandsstd::string_view. there are still a lot of static strings, especially in the*PrepareInfostructs, which are better suited toconst char*for use in the sqlite3 interfacesp.s. incidentially, this also resolves lots of compilation failures with c++20 enabled
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume tox