Under the hood | sourcemaps-lookup | Spatie

 SPATIE

sourcemaps-lookup
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Sourcemaps-lookup](https://spatie.be/docs/sourcemaps-lookup/v1)  Advanced-usage  Under the hood

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/sourcemaps-lookup/v1)

  Under the hood
- [ Introduction ](https://spatie.be/docs/sourcemaps-lookup/v1/introduction)
- [ Support us ](https://spatie.be/docs/sourcemaps-lookup/v1/support-us)
- [ Requirements ](https://spatie.be/docs/sourcemaps-lookup/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/sourcemaps-lookup/v1/installation-setup)
- [ Benchmarks ](https://spatie.be/docs/sourcemaps-lookup/v1/benchmarks)
- [ Questions and issues ](https://spatie.be/docs/sourcemaps-lookup/v1/questions-issues)
- [ About us ](https://spatie.be/docs/sourcemaps-lookup/v1/about-us)
- [ Changelog ](https://spatie.be/docs/sourcemaps-lookup/v1/changelog)

Basic usage
-----------

- [ Looking up a position ](https://spatie.be/docs/sourcemaps-lookup/v1/basic-usage/looking-up-a-position)
- [ Reading inlined source content ](https://spatie.be/docs/sourcemaps-lookup/v1/basic-usage/reading-source-content)
- [ Error handling ](https://spatie.be/docs/sourcemaps-lookup/v1/basic-usage/error-handling)
- [ Complete example ](https://spatie.be/docs/sourcemaps-lookup/v1/basic-usage/complete-example)

Advanced usage
--------------

- [ Reverse lookup ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/reverse-lookup)
- [ Resolving the enclosing scope ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/resolving-the-enclosing-scope)
- [ Marking third-party sources ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/marking-third-party-sources)
- [ Listing the source files ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/listing-source-files)
- [ Tips for bulk lookups ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/tips-for-bulk-lookups)
- [ Supported source map features ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/supported-features)
- [ Under the hood ](https://spatie.be/docs/sourcemaps-lookup/v1/advanced-usage/under-the-hood)

 Under the hood
==============

The package trades eager parsing for on demand, cached parsing.

- The raw `mappings` string is stored verbatim at construction.
- A `LineIndex` records the byte offset of every line in `mappings` via a tight `strpos` scan.
- On the first `lookup()` for a line, `LineParser` walks from the nearest cached VLQ state to the target line, decoding segments into a packed 20 byte per segment binary string (five signed int32s: generated column, source index, source line, source column, name index).
- Within the line, `lookup()` binary searches the packed buffer by generated column, unpacking only four bytes per probe. A full segment is materialised only for the winner.
- Parsed lines and their end of line VLQ state are cached, so later lookups on the same or later lines skip the work.

The result is that you pay for the lines you touch, and you never pay for PHP object overhead on segments you don't return.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
