-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
std.io.AnyWriter has very high overhead #21566
Copy link
Copy link
Closed
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.optimizationstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Metadata
Metadata
Assignees
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.optimizationstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Type
Fields
Give feedbackNo fields configured for issues without a type.
std.io.AnyWriter(and hencestd.io.GenericWriter, since that usesAnyWriterinternally) has a large amount of overhead in tight loops, as it hampers inlining.The following code snippet demonstrates an extreme case of the issue, but it comes up a lot in practice too:
EDIT (by @mlugg): the original numbers here were incorrect, since OP accidentally used
-Doptimizewithzig run. Accurate numbers from running this on my system are as follows:Using a custom buffering solution rather than
std.io.BufferedWriterresults in an approximately 2x speedup, simply by avoiding the overhead ofstd.io.AnyWriter.This pretty much defeats the whole point of having(EDIT @mlugg: this sentence was written based on incorrect performance numbers, which showed a wrongly exaggerated result.)BufferedWriterin the first place, sinceAnyWriterdestroys the good write performance it would otherwise provide.