Skip to content

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

Merged
Billy O'Neal (BillyONeal) merged 21 commits into
microsoft:masterfrom
sylveon:system_category_message_allocation
Feb 7, 2020
Merged

Billy O'Neal (BillyONeal) merged 21 commits into
microsoft:masterfrom
sylveon:system_category_message_allocation

Conversation

@sylveon

@sylveon Charles Milette (sylveon) commented Jan 24, 2020 •

Copy link
Copy Markdown
Contributor

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
Charles Milette (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

@BillyONeal Billy O'Neal (BillyONeal) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

Comment thread stl/inc/system_error Outdated
Comment thread stl/inc/system_error Outdated
Comment thread stl/inc/system_error Outdated
Comment thread stl/src/syserror.cpp Outdated
Comment thread stl/src/syserror.cpp Outdated
Comment thread stl/src/syserror.cpp Outdated

@BillyONeal Billy O'Neal (BillyONeal) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Charles Milette (@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
Copy Markdown
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
Copy Markdown
Contributor Author

LGTM

Comment thread stl/inc/__msvc_system_error_abi.hpp Outdated
Comment thread stl/inc/__msvc_system_error_abi.hpp Outdated
Comment thread stl/src/syserror_import_lib.cpp
Comment thread stl/src/syserror_import_lib.cpp
Comment thread stl/src/syserror_import_lib.cpp Outdated
Comment thread stl/src/syserror_import_lib.cpp Outdated
Comment thread stl/src/syserror_import_lib.cpp Outdated
Comment thread stl/src/syserror.cpp Outdated
Comment thread stl/src/syserror_import_lib.cpp Outdated
Comment thread stl/src/syserror_import_lib.cpp Outdated
Comment thread stl/src/syserror_import_lib.cpp Outdated
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
Comment thread stl/inc/__msvc_system_error_abi.hpp
Comment thread stl/inc/__msvc_system_error_abi.hpp Outdated
Comment thread stl/inc/__msvc_system_error_abi.hpp
Comment thread stl/inc/__msvc_system_error_abi.hpp
Comment thread stl/inc/__msvc_system_error_abi.hpp
Comment thread stl/src/syserror_import_lib.cpp
Comment thread stl/inc/system_error Outdated
Comment thread stl/inc/system_error Outdated
Comment thread stl/inc/system_error Outdated
Comment thread stl/inc/system_error Outdated
* 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 

Also:
* Fix link error in test
* constexprize error tables
Comment thread stl/src/syserror_import_lib.cpp Outdated
…sage_allocation

# Conflicts:
#	stl/src/syserror.cpp
Comment thread stl/src/syserror_import_lib.cpp Outdated
@BillyONeal
Billy O'Neal (BillyONeal) merged commit a8efb53 into microsoft:master Feb 7, 2020
@BillyONeal

Copy link
Copy Markdown
Member

Charles Milette (@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
Copy Markdown
Contributor Author

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.

: Consider improving memory allocation of system_category().message()

4 participants