notepad-plus-plus / notepad-plus-plus/notepad-plus-plus

[BUG] Performance issues with the intToString and uintToString functions

Open
#16,134 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance issue
Dominant language
C++
Stars
29.4k
Forks
5.4k
PR merge metrics
No merged PRs in 30d

Description

Is there an existing issue for this?
  • I have searched the existing issues
Description of the Issue

Performance issues with the intToString and uintToString functions

In the function intToString in Common.cpp, the current implementation has relatively low efficiency. It can be improved as follows:

The current version is:

wstring intToString(int val)
{
	std::vector<wchar_t> vt;
	bool isNegative = val < 0;
	// can't use abs here because std::numeric_limits<int>::min() has no positive representation
	//val = std::abs(val);

	vt.push_back('0' + static_cast<wchar_t>(std::abs(val % 10)));
	val /= 10;
	while (val != 0)
	{
		vt.push_back('0' + static_cast<wchar_t>(std::abs(val % 10)));
		val /= 10;
	}

	if (isNegative)
		vt.push_back('-');

	return wstring(vt.rbegin(), vt.rend());
}

After the improvement, when tested on my PC with 1,000,000 iterations, the current version takes about 1460 milliseconds, while the improved version takes about 220 milliseconds.

The code for the improved version is:

wstring intToString(int val) noexcept
{
	return std::to_wstring(val);
}
Steps To Reproduce

After the improvement, when tested on my PC with 1,000,000 iterations, the current version takes about 1460 milliseconds, while the improved version takes about 220 milliseconds.

Current Behavior

the current version takes about 1460 milliseconds

Expected Behavior

while the improved version takes about 220 milliseconds.

Debug Information
Notepad++ v8.7.5   (64-bit)
Build time : Dec 21 2024 - 05:13:03
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : 
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
Placeholders : OFF
DirectWrite : ON
Multi-instance Mode : monoInst
File Status Auto-Detection : cdEnabledNew (for current file/tab only)
Dark Mode : OFF
OS Name : Windows 11 Enterprise (64-bit)
OS Version : 23H2
OS Build : 22631.4751
Current ANSI codepage : 1252
Plugins : 
    mimeTools (3.1)
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review intToString and uintToString in Common.cpp, then compare their current behavior with the proposed standard-library approach, including integer edge cases. Benchmark the relevant conversion paths and confirm that both functions retain their expected output while improving performance.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.