Bun is designed for speed. Hot paths are extensively profiled and benchmarked. The source code for all of Bun's public benchmarks can be found in the [`/bench`](https://github.com/oven-sh/bun/tree/main/bench) directory of the Bun repo. ## Measuring time To precisely measure time, Bun offers two runtime APIs functions: 1. The Web-standard [`performance.now()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) function 2. `Bun.nanoseconds()` which is similar to `performance.now()` except it returns the current time since the application started in nanoseconds. You can use `performance.timeOrigin` to convert this to a Unix timestamp. ## Benchmarking tools When writing your own benchmarks, it's important to choose the right tool. - For microbenchmarks, a great general-purpose tool is [`mitata`](https://github.com/evanwashere/mitata). - For load testing, you _must use_ an HTTP benchmarking tool that is at least as fast as `Bun.serve()`, or your results will be skewed. Some popular Node.js-based benchmarking tools like [`autocannon`](https://github.com/mcollina/autocannon) are not fast enough. We recommend one of the following: - [`bombardier`](https://github.com/codesenberg/bombardier) - [`oha`](https://github.com/hatoo/oha) - [`http_load_test`](https://github.com/uNetworking/uSockets/blob/master/examples/http_load_test.c) - For benchmarking scripts or CLI commands, we recommend [`hyperfine`](https://github.com/sharkdp/hyperfine). ## Measuring memory usage Bun has two heaps. One heap is for the JavaScript runtime and the other heap is for everything else. {% anchor id="bunjsc" /%} ### JavaScript heap stats The `bun:jsc` module exposes a few functions for measuring memory usage: ```ts import { heapStats } from "bun:jsc"; console.log(heapStats()); ``` {% details summary="View example statistics" %} ```ts { heapSize: 1657575, heapCapacity: 2872775, extraMemorySize: 598199, objectCount: 13790, protectedObjectCount: 62, globalObjectCount: 1, protectedGlobalObjectCount: 1, // A count of every object type in the heap objectTypeCounts: { CallbackObject: 25, FunctionExecutable: 2078, AsyncGeneratorFunction: 2, 'RegExp String Iterator': 1, FunctionCodeBlock: 188, ModuleProgramExecutable: 13, String: 1, UnlinkedModuleProgramCodeBlock: 13, JSON: 1, AsyncGenerator: 1, Symbol: 1, GetterSetter: 68, ImportMeta: 10, DOMAttributeGetterSetter: 1, UnlinkedFunctionCodeBlock: 174, RegExp: 52, ModuleLoader: 1, Intl: 1, WeakMap: 4, Generator: 2, PropertyTable: 95, 'Array Iterator': 1, JSLexicalEnvironment: 75, UnlinkedFunctionExecutable: 2067, WeakSet: 1, console: 1, Map: 23, SparseArrayValueMap: 14, StructureChain: 19, Set: 18, 'String Iterator': 1, FunctionRareData: 3, JSGlobalLexicalEnvironment: 1, Object: 481, BigInt: 2, StructureRareData: 55, Array: 179, AbortController: 2, ModuleNamespaceObject: 11, ShadowRealm: 1, 'Immutable Butterfly': 103, Primordials: 1, 'Set Iterator': 1, JSGlobalProxy: 1, AsyncFromSyncIterator: 1, ModuleRecord: 13, FinalizationRegistry: 1, AsyncIterator: 1, InternalPromise: 22, Iterator: 1, CustomGetterSetter: 65, Promise: 19, WeakRef: 1, InternalPromisePrototype: 1, Function: 2381, AsyncFunction: 2, GlobalObject: 1, ArrayBuffer: 2, Boolean: 1, Math: 1, CallbackConstructor: 1, Error: 2, JSModuleEnvironment: 13, WebAssembly: 1, HashMapBucket: 300, Callee: 3, symbol: 37, string: 2484, Performance: 1, ModuleProgramCodeBlock: 12, JSSourceCode: 13, JSPropertyNameEnumerator: 3, NativeExecutable: 290, Number: 1, Structure: 1550, SymbolTable: 108, GeneratorFunction: 2, 'Map Iterator': 1 }, protectedObjectTypeCounts: { CallbackConstructor: 1, BigInt: 1, RegExp: 2, GlobalObject: 1, UnlinkedModuleProgramCodeBlock: 13, HashMapBucket: 2, Structure: 41, JSPropertyNameEnumerator: 1 } } ``` {% /details %} JavaScript is a garbage-collected language, not reference counted. It's normal and correct for objects to not be freed immediately in all cases, though it's not normal for objects to never be freed. To force garbage collection to run manually: ```js Bun.gc(true); // synchronous Bun.gc(false); // asynchronous ``` Heap snapshots let you inspect what objects are not being freed. You can use the `bun:jsc` module to take a heap snapshot and then view it with Safari or WebKit GTK developer tools. To generate a heap snapshot: ```ts import { generateHeapSnapshot } from "bun"; const snapshot = generateHeapSnapshot(); await Bun.write("heap.json", JSON.stringify(snapshot, null, 2)); ``` To view the snapshot, open the `heap.json` file in Safari's Developer Tools (or WebKit GTK) 1. Open the Developer Tools 2. Click "Timeline" 3. Click "JavaScript Allocations" in the menu on the left. It might not be visible until you click the pencil icon to show all the timelines 4. Click "Import" and select your heap snapshot JSON {% image alt="Import heap json" src="https://user-images.githubusercontent.com/709451/204428943-ba999e8f-8984-4f23-97cb-b4e3e280363e.png" caption="Importing a heap snapshot" /%} Once imported, you should see something like this: {% image alt="Viewing heap snapshot in Safari" src="https://user-images.githubusercontent.com/709451/204429337-b0d8935f-3509-4071-b991-217794d1fb27.png" caption="Viewing heap snapshot in Safari Dev Tools" /%} ### Native heap stats Bun uses mimalloc for the other heap. To report a summary of non-JavaScript memory usage, set the `MIMALLOC_SHOW_STATS=1` environment variable. and stats will print on exit. ```js MIMALLOC_SHOW_STATS=1 bun script.js # will show something like this: heap stats: peak total freed current unit count reserved: 64.0 MiB 64.0 MiB 0 64.0 MiB not all freed! committed: 64.0 MiB 64.0 MiB 0 64.0 MiB not all freed! reset: 0 0 0 0 ok touched: 128.5 KiB 128.5 KiB 5.4 MiB -5.3 MiB ok segments: 1 1 0 1 not all freed! -abandoned: 0 0 0 0 ok -cached: 0 0 0 0 ok pages: 0 0 53 -53 ok -abandoned: 0 0 0 0 ok -extended: 0 -noretire: 0 mmaps: 0 commits: 0 threads: 0 0 0 0 ok searches: 0.0 avg numa nodes: 1 elapsed: 0.068 s process: user: 0.061 s, system: 0.014 s, faults: 0, rss: 57.4 MiB, commit: 64.0 MiB ``` value='feat/define-data'>feat/define-data Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/examples/portfolio/.stackblitzrc (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2022-02-07feat: Added the ability to add custom themes/languages to Shiki (#2518)Gravatar Juan Martín Seery 42-56/+1429
* Replaced `shikiTheme` with `shikiConfig` * Code.astro now accepts custom themes/langs * Updated docs * Updated tests * Fixed language loading * Added customization examples * Updated documentation * Added more tests * Changelogs * Changed some spaces to tabs * Fixed typo in changesets * Moved tests fixtures * Rolled back changes to with-markdown-shiki * Removed lang example in docs * Optimized Code component * Try to fix windows errors * Try to see if this new tests work
2022-02-07Delete robots.txt (#2540)Gravatar Marcus Otterström 2-3/+0
* Delete robots.txt * Update tour component * Remove stray line from folder structure
2022-02-07[ci] yarn formatGravatar matthewp 1-1/+1
2022-02-07[ci] update lockfile (#2543)Gravatar Fred K. Schott 1-171/+178
Co-authored-by: FredKSchott <FredKSchott@users.noreply.github.com>
2022-02-07improve debug logs (#2537)Gravatar Fred K. Schott 3-4/+19
* improve debug logs * Update logger.ts
2022-02-07[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-06[ci] update lockfile (#2527)Gravatar Fred K. Schott 1-208/+238
Co-authored-by: FredKSchott <FredKSchott@users.noreply.github.com>
2022-02-06[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-05[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-04[ci] yarn formatGravatar natemoo-re 1-2/+3
2022-02-04fix: HTML/SVG boolean attributes (#2538)Gravatar Nate Moore 2-3/+21
* fix: HTML/SVG boolean attributes * fix: update case-sensitivity of attributes * Update packages/astro/src/runtime/server/index.ts Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com> Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com>
2022-02-04[ci] yarn formatGravatar matthewp 1-4/+2
2022-02-04fix: import local plugins into markdown (#2534)Gravatar Juan Martín Seery 9-22/+41
* Replaced "UnifiedPluginImport" for a function * Updated tests * Updated docs * Updated examples * Added changeset * Fixed tests * Removed unused "UnifiedPluginImport" * Duplicated add-classes.mjs
2022-02-04[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03Append to list of HMR modules, don't override (#2532)Gravatar Matthew Phillips 2-1/+6
* Append to list of HMR modules, don't override * Changeset
2022-02-03add back dev server host support (#2531)Gravatar Fred K. Schott 2-1/+14
2022-02-03simplify status code regexGravatar Fred K. Schott 2-87/+4
2022-02-03Adding StackUp Digital to the list of sponsors (#2521)Gravatar Astroalex 3-0/+10
* adding svg files for stackup * Change list of sponsors w/testing * change back to withastro, done testing
2022-02-03[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03[ci] yarn formatGravatar FredKSchott 2-3/+85
2022-02-02Handles all http error code file names the same as 404 files. (#2525)Gravatar Zade Viggers 2-4/+7
* Fix #2195 * Filter out error code files from sitemap
2022-02-02fix(sitemap): remove debug if sitemap disabled (#2514)Gravatar Mark Pinero 1-2/+2
2022-02-02[ci] update lockfile (#2515)Gravatar Fred K. Schott 1-276/+279
Co-authored-by: FredKSchott <FredKSchott@users.noreply.github.com>
2022-02-02[ci] yarn formatGravatar matthewp 1-8/+8
2022-02-02[ci] release (next) (#2523)astro@0.23.0-next.1Gravatar github-actions[bot] 28-34/+41
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-02-02[ci] yarn formatGravatar matthewp 2-17/+29
2022-02-02Fix support for scss in static build (#2522)Gravatar Matthew Phillips 6-20/+114
* Fix support for scss in static build * Adds a changeset * Pass the normalizedID to transformWithVite
2022-02-02[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-01[ci] yarn formatGravatar matthewp 2-12/+12
2022-02-01[ci] release (next) (#2492)astro@0.23.0-next.0@astrojs/test-static-build-pkg@0.0.2@astrojs/markdown-remark@0.6.1-next.0Gravatar github-actions[bot] 31-43/+93
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-02-01[ci] collect statsGravatar FredKSchott 1-0/+1
2022-01-31update congratsbot format againGravatar Fred K. Schott 1-1/+1
2022-01-31update congratsbot againGravatar Fred K. Schott 1-1/+1
2022-01-31Remove SVG animation on GitHub/NPM (#2512)Gravatar Nate Moore 1-21/+0
* perf: remove SVG animation * update readme * Revert "update readme" This reverts commit 71abb6629d51d08ec7a50890ecf44140f6bc6b35.
2022-01-31[ci] yarn formatGravatar natemoo-re 2-4/+6
2022-01-31Add Shiki as an alternative to Prism (#2497)Gravatar Juan Martín Seery 26-9/+356
* [ci] yarn format * Added shiki to markdown-remark * Upgraded astro shiki * Added minimal example * Changed defaults to match <Code /> * Replace `shiki` with `astro` classes * Added documentation * Updated Astro code to use new `codeToHtml` * Added changesets * Added basic test * Updated tests a bit Co-authored-by: JuanM04 <JuanM04@users.noreply.github.com>
2022-01-31Deprecate unescaped HTML inside of expressions (#2489)Gravatar Nate Moore 9-31/+74
* feat: implement automatic escaping * feat: deprecate automatic escaping * fix: cast unescapeHTML as string * fix: slot fallback behavior * fix: unescaped content * Update escape.ts * Update escape.ts * feat: update internal components to use `set:html` * chore: update compiler * chore: update changeset