New submission from STINNER Victor: Example:
with open("x", "w", encoding="utf-8") as fp: fp.write("HERE") fp.close() syscalls: 14249 open("x", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3 14249 fstat(3, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0 14249 ioctl(3, TCGETS, 0x7fff07d43330) = -1 ENOTTY (Inappropriate ioctl for device) 14249 lseek(3, 0, SEEK_CUR) = 0 14249 lseek(3, 0, SEEK_CUR) = 0 14249 lseek(3, 0, SEEK_CUR) = 0 14249 write(3, "HERE", 4) = 4 14249 close(3) = 0 I only expected 3 syscalls: open, write, close. * fstat() is used by the FileIO constructor to check if the file is a directory or not, and to get the block size * ioctl() comes from open() which checks if the file is a TTY or not, to decide how to configure buffering * the first lseek() is used by the BuffererWriter constructor to initialize the private abs_pos attribute * the second lseek() is used by the TextIOWrapper constructor to check if the underlying file object (buffered writer) is seekable or not * the last lseek() is used to create the cookie object in TextIOWrapper constructor Can we maybe reduce the number of lseek() to a single syscall? For example, BuffererWriter constructor calls FileIO.tell(): can't this method set the seekable attribute depending on lseek() success, as the FileIO.seekable property? ---------- messages: 292744 nosy: haypo, pitrou, serhiy.storchaka priority: normal severity: normal status: open title: Open a file in text mode requires too many syscalls type: performance versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30228> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com