Skip to content

Reduce memory consumption of system_category().message()#457

Merged
BillyONeal merged 21 commits intomicrosoft:masterfrom
sylveon:system_category_message_allocation
Feb 7, 2020
Merged

Reduce memory consumption of system_category().message()#457
BillyONeal merged 21 commits intomicrosoft:masterfrom
sylveon:system_category_message_allocation

Conversation

@sylveon
Copy link
Contributor

@sylveon sylveon commented Jan 24, 2020

Description

This avoids the allocation in _Winerror_message, and introduces a new version of it which uses FORMAT_MESSAGE_ALLOCATE_BUFFER to completely avoid overallocating memory

Fixes #434

Checklist

Be sure you've read README.md and understand the scope of this repo.

If you're unsure about a box, leave it unchecked. A maintainer will help you.

  • Identifiers in product code changes are properly _Ugly as per
    https://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
  • The STL builds successfully and all tests have passed (must be manually
    verified by an STL maintainer before automated testing is enabled on GitHub,
    leave this unchecked for initial submission).
  • These changes introduce no known ABI breaks (adding members, renaming
    members, adding virtual functions, changing whether a type is an aggregate
    or trivially copyable, etc.).
  • These changes were written from scratch using only this repository,
    the C++ Working Draft (including any cited standards), other WG21 papers
    (excluding reference implementations outside of proposed standard wording),
    and LWG issues as reference material. If they were derived from a project
    that's already listed in NOTICE.txt, that's fine, but please mention it.
    If they were derived from any other project (including Boost and libc++,
    which are not yet listed in NOTICE.txt), you must mention it here,
    so we can determine whether the license is compatible and what else needs
    to be done.

@sylveon sylveon requested a review from a team as a code owner January 24, 2020 23:59
This avoids the allocation in _Winerror_message, and introduces a new version of it which uses FORMAT_MESSAGE_ALLOCATE_BUFFER to completely avoid overallocating memory

Fixes #434
Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@BillyONeal BillyONeal self-assigned this Feb 1, 2020
@BillyONeal BillyONeal self-requested a review February 1, 2020 03:48
Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylveon I've extracted the new functions into the import lib so that we can avoid breaking the ABI of msvcp140.dll. Please look this over after my changes and make sure you're happy with them.

Thanks for your contribution!

@BillyONeal
Copy link
Member

Thank you, you did the hard part. I just mostly copy/pasta'd code around to make the old build system in devdiv happy :)

@sylveon
Copy link
Contributor Author

sylveon commented Feb 1, 2020

LGTM

sylveon and others added 4 commits February 3, 2020 15:46
LocalFree already ignores arguments that are nullptr, and _System_error_message does not relies on the return value when deciding whether to free, meaning we can return 0 if the message is entirely whitespaces since the caller will clean up the message unconditionally
@BillyONeal BillyONeal self-requested a review February 4, 2020 05:43
* Make __msvc headers use consistent header guards.
* Add tests for __std_get_string_size_without_trailing_whitespace.
* Add nodiscard and explicit to things
* Remove SAL
* free => deallocate
* Remove blank lines in places
* Terse get_string_size loop
* constexprize string length
* Workaround DevCom-906503
* Remove no longer used <cstdlib>

Also:
* Fix link error in test
* constexprize error tables
@StephanTLavavej StephanTLavavej added the performance Must go faster label Feb 5, 2020
…sage_allocation

# Conflicts:
#	stl/src/syserror.cpp
@BillyONeal BillyONeal merged commit a8efb53 into microsoft:master Feb 7, 2020
@BillyONeal
Copy link
Member

@sylveon Thanks again for your contribution!

fengjixuchui added a commit to fengjixuchui/STL that referenced this pull request Feb 7, 2020
Reduce memory consumption of system_category().message() (microsoft#457)
@sylveon
Copy link
Contributor Author

sylveon commented Feb 7, 2020

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<system_error>: Consider improving memory allocation of system_category().message()

4 participants