Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开启“自动换行”时打开大文件速度非常慢。 #957

Open
softmgr opened this issue Jan 7, 2025 · 8 comments
Open

开启“自动换行”时打开大文件速度非常慢。 #957

softmgr opened this issue Jan 7, 2025 · 8 comments

Comments

@softmgr
Copy link

softmgr commented Jan 7, 2025

在关闭“自动换行”时,打开一个大文件非常快,且可以在语法高亮渲染未完成时将光标定位到文件尾(按组合键Ctrl+End)。
在开启“自动换行”后,打开大文件非常慢,且语法高亮渲染会一直卡住,直到语法高亮渲染完成后,才能进行编辑操作(例如按组合键Ctrl+End没有响应,需要等很久才能响应操作)。

测试方法:
打开或关闭“自动换行”后,再打开一个大文件(我测试了200MB的html文件),马上按组合键Ctrl+End。

@zufuliu
Copy link
Owner

zufuliu commented Jan 9, 2025

Commit bbe02d6 optimized HTML highlighting.
Word wrap is known to slow for large file.

@softmgr
Copy link
Author

softmgr commented Jan 9, 2025

Commit bbe02d6 optimized HTML highlighting.

Word wrap is known to slow for large file.

不是html引起的。即使是txt文件也是一样的。

@softmgr
Copy link
Author

softmgr commented Jan 17, 2025

@zufuliu 此问题有进展吗?

@zufuliu
Copy link
Owner

zufuliu commented Jan 17, 2025

此问题有进展吗?

No.

@softmgr
Copy link
Author

softmgr commented Jan 17, 2025

此问题有进展吗?

No.

我也跟踪过代码,它是在自动换行切换时,运行到 Editor.cxx 中的代码:

void Editor::InvalidateStyleRedraw() {
	NeedWrapping();
	InvalidateStyleData();
	Redraw();
}

接着,再进行消息WM_PAINT的过程中变得无响应的。它在进行界面刷新进行了大量的运算,我猜这些运算应该是可以优化的。

@zufuliu
Copy link
Owner

zufuliu commented Jan 17, 2025

Scintilla 5.3.4 added multithreaded word wrap (useful for large file with many short lines) but is still not adopted for Notepad4 (needs to figure out when multithreaded is benefit, https://sourceforge.net/p/scintilla/feature-requests/1481/).

@softmgr
Copy link
Author

softmgr commented Jan 17, 2025

多线程换行还是会卡顿,这个在n++中已经测试过了。

@softmgr
Copy link
Author

softmgr commented Jan 23, 2025

@zufuliu 我今天找到一些线索,切换自动换行时(从关闭切换到打开自动换行),此时CPU占用率会变高几秒钟,在此期间可以使用鼠标点击和滚动界面,都能流畅定位光标,这很好。但是,如果马上按键盘上的方向键(从文件尾,按上方向键),则整个编辑器会立即失去响应,直到前面说的CPU占用率下降后,光标位置才能得到响应。这一现象在np4,np++中都得到了一样的测试结果:这充分说明它是scintilla组件的性能问题。

经测试,修改 Editor.cxx 的代码,可以解决上述提到的问题。

void Editor::MovedCaret(SelectionPosition newPos, SelectionPosition previousPos,
	bool ensureVisible, CaretPolicies policies) {
	const Sci::Line currentLine = pdoc->SciLineFromPosition(newPos.Position());
	if (ensureVisible) {
		// In case in need of wrapping to ensure DisplayFromDoc works.
		if (currentLine >= wrapPending.start) {
			//if (WrapLines(WrapScope::wsAll)) {
			//	Redraw();
			//}
			WrapLines(WrapScope::wsIdle); // 修改为此行代码
		}
		// ...
	}
	// ...
}

但它不能完全解决此主题中的问题:在打开自动换行的时候,打开文件之后,立即按Ctrl+End,还是会卡住。

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

No branches or pull requests

2 participants