Skip to content

Repeated terminfo db opens #1800

Closed
Closed
@rbtcollins

Description

@rbtcollins

Problem
rustup is opening the terminfo db repeatedly, which is wasteful.

Steps
Run rustup under strace / process monitor; debug builds are useful to get good stacks :).

3:54:41.7794556 PM	rustup.exe	972	CreateFile	C:\Users\robertc\.terminfo	NAME NOT FOUND	Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:54:41.7795392 PM	rustup.exe	972	CreateFile	C:\etc\terminfo	PATH NOT FOUND	Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:54:41.7795954 PM	rustup.exe	972	CreateFile	C:\lib\terminfo	PATH NOT FOUND	Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:54:41.7796514 PM	rustup.exe	972	CreateFile	C:\usr\share\terminfo	PATH NOT FOUND	Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:54:41.7797046 PM	rustup.exe	972	CreateFile	C:\boot\system\data\terminfo	PATH NOT FOUND	Desired Access: Read Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a

This shows up multiple times

A sample stack fragment

14	rustup.exe	std::sys::windows::fs::File::open + 0x1e7, /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys\windows\fs.rs(256)	0x7ff66d20fa77	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
15	rustup.exe	std::sys::windows::fs::stat + 0x57, /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys\windows\fs.rs(676)	0x7ff66d210ae7	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
16	rustup.exe	std::fs::metadata<std::path::PathBuf*> + 0x4e, /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\fs.rs(867)	0x7ff66c4691fe	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
17	rustup.exe	term::terminfo::searcher::get_dbpath_for_term + 0xb49, C:\Users\robertc\.cargo\registry\src\github.com-1ecc6299db9ec823\term-0.5.2\src\terminfo\searcher.rs(73)	0x7ff66c445dc9	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
18	rustup.exe	term::terminfo::TermInfo::from_name + 0x65, C:\Users\robertc\.cargo\registry\src\github.com-1ecc6299db9ec823\term-0.5.2\src\terminfo\mod.rs(93)	0x7ff66c457315	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
19	rustup.exe	term::terminfo::TermInfo::from_env + 0x178, C:\Users\robertc\.cargo\registry\src\github.com-1ecc6299db9ec823\term-0.5.2\src\terminfo\mod.rs(85)	0x7ff66c457168	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
20	rustup.exe	term::terminfo::TerminfoTerminal<std::io::stdio::Stderr>::new<std::io::stdio::Stderr> + 0x44, C:\Users\robertc\.cargo\registry\src\github.com-1ecc6299db9ec823\term-0.5.2\src\terminfo\mod.rs(384)	0x7ff66c45a394	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
21	rustup.exe	term::stderr + 0x20, C:\Users\robertc\.cargo\registry\src\github.com-1ecc6299db9ec823\term-0.5.2\src\lib.rs(1)	0x7ff66c4462e0	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe
22	rustup.exe	rustup_init::term2::stderr + 0x9, C:\Users\robertc\Documents\src\rustup.rs\src\cli\term2.rs(56)	0x7ff66c41c289	C:\Users\robertc\Documents\src\rustup.rs\target\debug\rustup.exe

Possible Solution(s)

The term library does no caching of the environment; it looks likes complete minimisation requires retaining the terminfo db and use term::terminfo::TerminfoTerminal new_with_terminfo rather than the stdout and stderr helpers.

A probably fine intermediate step is to open stdout and stderr just once each and manage those resources.

Notes

This is in git as of 373448b
Output of rustup --version:
Output of rustup show:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions