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

IoResult bloats return values #12294

Closed
mneumann opened this issue Feb 15, 2014 · 7 comments
Closed

IoResult bloats return values #12294

mneumann opened this issue Feb 15, 2014 · 7 comments

Comments

@mneumann
Copy link
Contributor

IoResult adds 3 words to every function that returns it:

pub type IoResult<T> = Result<T, IoError>;

pub struct IoError {
    kind: IoErrorKind,
    desc: &'static str,
    detail: Option<~str>,
}

Wouldn't it be better to retrieve the exact error information out of the underlying reader/writer. I know that this introduces state which has some other problems. My idea is to simply return an Ok(T) or Err in the same way as Go handles this.

@adrientetar
Copy link
Contributor

@zkamsler
Copy link
Contributor

I am doubtful about this. Moving the error into the underlying reader or writer makes it very difficult to bubble up errors. The ultimate caller may not even have direct access to the original source of the error. In addition, there are some methods that return an IoResult that do not take &mut self, such as Seek::tell.

@sfackler
Copy link
Member

Have you seen a measurable performance impact from use of IoResult?

@mneumann
Copy link
Contributor Author

Returning an IoResult makes sense for unbuffered I/O operations, but when byte-wise iterating a BufferedStream for example, this probably has some significant overhead. I think the current implementation is not optimal yet, or maybe I just have to implement my own buffering.

@alexcrichton
Copy link
Member

It would be helpful for you to provide concrete test cases and performance numbers in order to debug this. Stating that IoResult<T> adds 3 words is a factual statement, but stating that it cause significant overhead is tough to understand without any data supporting it.

@mneumann
Copy link
Contributor Author

Ok, I'll try to come up with a benchmark.

@mneumann
Copy link
Contributor Author

I benchmarked my msgpack library, once with rustc 0.9 and then with rustc-0.10-pre as of today on a 120 MB msgpack file. I couldn't notice any difference in performance.

I have looked at the assembly output. The only difference is that it allocates more stack space for the bigger error result.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
Switch to Prettier for TypeScript Code formatting

## Summary of changes:

 1. Added [`.editorconfig` file](https://editorconfig.org) to dictate general hygienic stuff like character encoding, no trailing whitespace, new line symbols etc. for all files (e.g. Markdown). Install an editor plugin to get this rudimentary formatting assistance automatically. Prettier can read this file and, for example, use it for indentation style and size.
 2. Added a minimal prettier config file. All options are default except line width, which per [Veykril](https://github.com/Veykril) suggestion is set to 100 instead of 80, because [that's what `Rustfmt` uses](https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#max_width).
 3. Change `package.json` to use Prettier instead of `tsfmt` for code formatting.
 4. Performed initial formatting in a separate commit, per [bjorn3](https://github.com/bjorn3) suggestion added its hash to a `.git-blame-ignore-revs` file. For it to work you need to add a configuration to your git installation:
    ```Shell
    git config --global blame.ignoreRevsFile .git-blame-ignore-revs
    ```
 5. Finally, removed `typescript-formatter` from the list of dependencies.

----
What follows below is summary of the discussion we had on Zulip about the formatter switch:

## Background

For the context, there are three reasons why we went with `tsfmt` originally:
* stick to vscode default/built-in
* don't add extra deps to package.json.lock
* follow upstream (language server node I think still uses `tsfmt`)

And the meta reason here was that we didn't have anyone familiar with frontend, so went for the simplest option, at the expense of features and convenience.

Meanwhile, [**Prettier**](https://prettier.io) became a formatter project that JS community consolidated on a few years ago. It's similar to `go fmt` / `cargo fmt` in spirit: minimal to no configuration to promote general uniformity in the ecosystem. There are some options, that were needed early on to make sure the project gained momentum, but by no means it's a customizable formatter that is easy to adjust to reduce the number of changes for adoption.

## Overview of changes performed by Prettier

Some of the changes are acceptable. Prettier dictates a unified string quoting style, and as a result half of our imports at the top are changed. No one would mind that. Some one-line changes are due to string quotes, too, and although these a re numerous, the surrounding lines aren't changed, and git blame / GitLens will still show relevant context.

Some are toss ups. `trailingComma` option - set it to `none`, and get a bunch of meaningless changes in half of the code. set it to `all` and get a bunch of changes in the other half of the code. Same with using parentheses around single parameters in arrow functions: `x => x + 1` vs `(x) => x + 1`. Perrier forces one style or the other, but we use both in our code.

Like I said, the changes above are Ok - they take a single line, don't disrupt GitLens / git blame much. **The big one is line width**. Prettier wants you to choose one and stick to it. The default is 80 and it forces some reformatting to squish deeply nested code or long function type declarations. If I set it to 100-120, then Prettier finds other parts of code where a multi-line expression can be smashed into a single long line. The problem is that in both cases some of the lines that get changed are interesting, they contain somewhat non-trivial logic, and if I were to work on them in future I would love to see the commit annotations that tell me something relevant. Alas, we use some of that.

## Project impact

Though Prettier is a mainstream JS project it has no dependencies. We add another package so that it and ESLint work together nicely, and that's it.
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 26, 2024
…=Jarcho

Check trait items in `min_ident_chars`

Fix rust-lang#12237.

changelog: [`min_ident_chars`]: check trait items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants