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

Replace string concatenation in loop with string builder #505

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

appgurueu
Copy link
Contributor

For large input files, the string concatenation in a hot loop done to trim lines is a bottleneck, running in quadratic time since it has to copy the current string every time. Using a string builder, this can be optimized in linear time.
For Minetest's large lua_api.md, this brings the time down from 45s to 3s, a 15x speedup, on my laptop.

@LizzyFleckenstein03
Copy link

This is indeed a huge speed up.
On my machine rendering minetest's lua_api.md takes

  • 32.57s before this change. flamegraph:

flamegraph_before

  • 1.94s after this change. flamegraph:

flamegraph_after

@emmanueltouzery
Copy link

I don't understand why this PR doesn't get merged. I see huge advantages and zero downside?

@caarlos0 caarlos0 merged commit 9a3f7a1 into charmbracelet:master Aug 24, 2023
@caarlos0
Copy link
Member

thanks for the PR! (and sorry we took some time to merge)

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 28, 2024
⚠️ **CAUTION: this is a major update, indicating a breaking change!** ⚠️

This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [charmbracelet/glow](https://github.com/charmbracelet/glow) | major | `v1.5.1` -> `v2.0.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>charmbracelet/glow (charmbracelet/glow)</summary>

### [`v2.0.0`](https://github.com/charmbracelet/glow/releases/tag/v2.0.0)

[Compare Source](charmbracelet/glow@v1.5.1...v2.0.0)

### Hello v2!

This release contains a massive amount of bug fixes and rendering improvements, many of which come by way of [Glamour v0.8.0](https://github.com/charmbracelet/glamour/releases/tag/v0.8.0) which was released a few weeks ago.

As a bonus, the latest version of Glamour includes support for Tokyo Night.

```bash
glow -s "tokyo-night"
```

<img alt="Tokyo Night x Glamour" src="https://github.com/charmbracelet/glamour/blob/master/styles/gallery/tokyo-night.png" width="600">

Additionally, the stash feature has been removed.

#### Changelog

##### New!

-   [`d89d79a`](charmbracelet/glow@d89d79a): feat: --preserve-new-lines ([#&#8203;623](charmbracelet/glow#623)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`b1d3772`](charmbracelet/glow@b1d3772): feat: add 'r' to refresh list and document ([#&#8203;624](charmbracelet/glow#624)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`96d2a38`](charmbracelet/glow@96d2a38): feat: allow --width=0 to disable wordwrap ([#&#8203;366](charmbracelet/glow#366)) ([@&#8203;applejag](https://github.com/applejag))
-   [`fe066f2`](charmbracelet/glow@fe066f2): feat: allow config from CHARM_CONFIG_HOME and XDG_CONFIG_HOME ([#&#8203;621](charmbracelet/glow#621)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`9ebe39c`](charmbracelet/glow@9ebe39c): feat: improve gitlab/github readme url ([#&#8203;456](charmbracelet/glow#456)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`f1cf0ba`](charmbracelet/glow@f1cf0ba): feat: man pages ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`597e56b`](charmbracelet/glow@597e56b): feat: open editor in current line ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`d7032fe`](charmbracelet/glow@d7032fe): feat: shell completions ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`2d5bd3b`](charmbracelet/glow@2d5bd3b): feat: show line numbers configuration option ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`0dcf127`](charmbracelet/glow@0dcf127): feat: suspend ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`c991ec4`](charmbracelet/glow@c991ec4): feat: use x/editor ([#&#8203;543](charmbracelet/glow#543)) ([@&#8203;caarlos0](https://github.com/caarlos0))

##### Fixed!

-   [`9c79fa1`](charmbracelet/glow@9c79fa1): fix(ci): remove soft-serve workflow ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
-   [`bccf3d0`](charmbracelet/glow@bccf3d0): fix(ci): update coverage workflow ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
-   [`08c564c`](charmbracelet/glow@08c564c): fix: --all bypass .gitignore rules ([#&#8203;285](charmbracelet/glow#285)) ([#&#8203;504](charmbracelet/glow#504)) ([@&#8203;aitva](https://github.com/aitva))
-   [`8e51396`](charmbracelet/glow@8e51396): fix: check other possible readme paths/branches ([#&#8203;450](charmbracelet/glow#450)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`1133e50`](charmbracelet/glow@1133e50): fix: config failing in tests ([#&#8203;625](charmbracelet/glow#625)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`2288311`](charmbracelet/glow@2288311): fix: do not hard fail if no config ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`821d51d`](charmbracelet/glow@821d51d): fix: do not show absolute path as note ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`247c707`](charmbracelet/glow@247c707): fix: glow URL ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`a1a8563`](charmbracelet/glow@a1a8563): fix: handle not being able to create log file ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`b80e831`](charmbracelet/glow@b80e831): fix: handle permission denied ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`54dd62a`](charmbracelet/glow@54dd62a): fix: handle running inside a snap ([#&#8203;527](charmbracelet/glow#527)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`ad01f38`](charmbracelet/glow@ad01f38): fix: improve line no ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`f44e5b5`](charmbracelet/glow@f44e5b5): fix: improve message ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`7e471f1`](charmbracelet/glow@7e471f1): fix: lint issue ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`e4cacf7`](charmbracelet/glow@e4cacf7): fix: mkdir cache dir ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`1407793`](charmbracelet/glow@1407793): fix: pass color profile down to glamour ([#&#8203;626](charmbracelet/glow#626)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`9a3f7a1`](charmbracelet/glow@9a3f7a1): fix: replace string concatenation in loop with string builder ([#&#8203;505](charmbracelet/glow#505)) ([@&#8203;appgurueu](https://github.com/appgurueu))
-   [`cd99146`](charmbracelet/glow@cd99146): fix: update codeowners ([#&#8203;637](charmbracelet/glow#637)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`3f9102d`](charmbracelet/glow@3f9102d): fix: yet another log handling fix ([@&#8203;caarlos0](https://github.com/caarlos0))

##### Deps

-   [`c89c8bd`](charmbracelet/glow@c89c8bd): feat: update glamour ([#&#8203;634](charmbracelet/glow#634)) ([@&#8203;caarlos0](https://github.com/caarlos0))
-   [`4578bc1`](charmbracelet/glow@4578bc1): feat: updating glamour ([#&#8203;631](charmbracelet/glow#631)) ([@&#8203;caarlos0](https://github.com/caarlos0))

##### Other Stuff

-   [`d2e7742`](charmbracelet/glow@d2e7742): chore(ci): enable gofumpt ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
-   [`736e77d`](charmbracelet/glow@736e77d): feat!: rename module to /v2 ([#&#8203;640](charmbracelet/glow#640)) ([@&#8203;caarlos0](https://github.com/caarlos0))

***

<details>
<summary>Verifying the artifacts</summary>

First, download the [`checksums.txt` file](https://github.com/charmbracelet/glow/releases/download/2.0.0/checksums.txt), for example, with `wget`:

```bash
wget 'https://github.com/charmbracelet/glow/releases/download/v2.0.0/checksums.txt'
```

Then, verify it using [`cosign`](https://github.com/sigstore/cosign):

```bash
cosign verify-blob \
  --certificate-identity 'https://github.com/charmbracelet/meta/.github/workflows/goreleaser.yml@refs/heads/main' \
  --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
  --cert 'https://github.com/charmbracelet/glow/releases/download/v2.0.0/checksums.txt.pem' \
  --signature 'https://github.com/charmbracelet/glow/releases/download/v2.0.0/checksums.txt.sig' \
  ./checksums.txt
```

If the output is `Verified OK`, you can safely use it to verify the checksums of other artifacts you downloaded from the release using `sha256sum`:

```bash
sha256sum --ignore-missing -c checksums.txt
```

Done! You artifacts are now verified!

</details>

<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>

Thoughts? Questions? We love hearing from you. Feel free to reach out on [Twitter](https://twitter.com/charmcli), [The Fediverse](https://mastodon.technology/@&#8203;charm), or on [Discord](https://charm.sh/chat).

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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

Successfully merging this pull request may close these issues.

5 participants