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

[Turbopack] remove exceeding cells #69059

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9d1592f
add new backend
sokra Jul 26, 2024
023f16e
new backend
sokra Jul 29, 2024
32b447a
add more backend method implementations
sokra Aug 2, 2024
fcea2fd
very basic operation working
sokra Aug 7, 2024
c6f4e70
add own cells reading
sokra Aug 7, 2024
db0bc43
call transient tasks
sokra Aug 7, 2024
ca6cbb4
call persistent tasks
sokra Aug 7, 2024
da0f04c
run tests multiple times to test caching
sokra Aug 7, 2024
41d716c
add cell/output reading and creating cached tasks
sokra Aug 7, 2024
f573143
serialization fixup
sokra Aug 9, 2024
5029e1c
remove unused stuff
sokra Aug 9, 2024
ed8b087
clippy
sokra Aug 9, 2024
2fb17f3
remove things not yet used (persistence)
sokra Aug 9, 2024
0d8a666
clippy
sokra Aug 9, 2024
37df4cc
add more tests for new backend
sokra Aug 9, 2024
eb0b6c9
add support for connect_child
sokra Aug 13, 2024
78af7a5
set root type on root tasks
sokra Aug 9, 2024
ffc9e21
remove old edges when task recomputation completes
sokra Aug 12, 2024
c448018
add try_get_function_id
sokra Aug 14, 2024
b0977cb
Revert "remove things not yet used (persistence)"
sokra Aug 9, 2024
dd40246
add lmdb persisting and restoring
sokra Aug 8, 2024
bdec3c3
pass test name to test_config to construct db name
sokra Aug 9, 2024
2cce8d9
continue uncompleted operations
sokra Aug 9, 2024
d3fcc67
create dir and logging
sokra Aug 12, 2024
024c2f1
improve error messages
sokra Aug 13, 2024
95e3f2c
handle keys larger than 511 bytes
sokra Aug 13, 2024
6dac853
set root type on root tasks
sokra Aug 9, 2024
4d5b42e
move backend impl into type alias
sokra Aug 12, 2024
733d42a
add new backend feature
sokra Aug 12, 2024
c736b0d
add missing import
sokra Aug 14, 2024
36b118c
initial aggregation update
sokra Aug 13, 2024
03abe58
enable new backend
sokra Aug 13, 2024
686c198
WIP: remove todos
sokra Aug 13, 2024
e126a75
more aggregation operations
sokra Aug 13, 2024
bc62ead
handle state serialization
sokra Aug 14, 2024
aa5ec04
validate serialization and improve errors
sokra Aug 14, 2024
c39ec7d
avoid some serde skip and untagged
sokra Aug 14, 2024
40aab63
use TransientState
sokra Aug 14, 2024
1aa5572
validate serialization and improve errors
sokra Aug 14, 2024
4835ae1
store project options in state
sokra Aug 14, 2024
44e902a
show lookup error
sokra Aug 14, 2024
d4f7561
log restored db entries
sokra Aug 14, 2024
26b7652
improve error
sokra Aug 14, 2024
2a0dd5a
improve benchmark_file_io for persistent cache
sokra Aug 14, 2024
4866761
WIP: print new tasks
sokra Aug 14, 2024
6db46f3
gracefully stop turbo-tasks to allow persisting to complete
sokra Aug 14, 2024
a96143d
avoid storing transient tasks
sokra Aug 14, 2024
92aff18
WIP: logging
sokra Aug 14, 2024
15950e6
remove exceeding cells
sokra Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle keys larger than 511 bytes
  • Loading branch information
sokra committed Sep 4, 2024
commit 95e3f2cedef927fd7d50ba3114fb25a2d113ff1c
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
auto-hash-map = { workspace = true }
bincode = "1.3.3"
byteorder = "1.5.0"
dashmap = { workspace = true }
indexmap = { workspace = true }
lmdb = "0.8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod extended_key;

use std::{
collections::{hash_map::Entry, HashMap},
error::Error,
Expand Down Expand Up @@ -118,7 +120,8 @@ impl BackingStorage for LmdbBackingStorage {
let task_id = **task_id;
let task_type_bytes = bincode::serialize(&task_type)
.with_context(|| anyhow!("Unable to serialize task cache key {task_type:?}"))?;
tx.put(
extended_key::put(
&mut tx,
self.forward_task_cache_db,
&task_type_bytes,
&task_id.to_be_bytes(),
Expand Down Expand Up @@ -204,8 +207,7 @@ impl BackingStorage for LmdbBackingStorage {
fn forward_lookup_task_cache(&self, task_type: &CachedTaskType) -> Option<TaskId> {
let tx = self.env.begin_ro_txn().ok()?;
let task_type = bincode::serialize(task_type).ok()?;
let result = tx
.get(self.forward_task_cache_db, &task_type)
let result = extended_key::get(&tx, self.forward_task_cache_db, &task_type)
.ok()
.and_then(|v| v.try_into().ok())
.map(|v| TaskId::from(u32::from_be_bytes(v)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use std::hash::{Hash, Hasher};

use byteorder::ByteOrder;
use lmdb::{Database, RoTransaction, RwTransaction, Transaction, WriteFlags};
use rustc_hash::FxHasher;

const MAX_KEY_SIZE: usize = 511;
const SHARED_KEY: usize = MAX_KEY_SIZE - 8;

pub fn get<'tx>(
tx: &'tx RoTransaction<'tx>,
database: Database,
key: &[u8],
) -> lmdb::Result<&'tx [u8]> {
if key.len() > MAX_KEY_SIZE - 1 {
let hashed_key = hashed_key(key);
let data = tx.get(database, &hashed_key)?;
let mut iter = ExtendedValueIter::new(data);
while let Some((k, v)) = iter.next() {

Check failure on line 19 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage/extended_key.rs

View workflow job for this annotation

GitHub Actions / rust check / build

this loop could be written as a `for` loop
if k == key {
return Ok(v);
}
}
Err(lmdb::Error::NotFound)
} else {
tx.get(database, &key)
}
}

pub fn put(
tx: &mut RwTransaction<'_>,
database: Database,
key: &[u8],
value: &[u8],
flags: WriteFlags,
) -> lmdb::Result<()> {
if key.len() > MAX_KEY_SIZE - 1 {
let hashed_key = hashed_key(key);

let size = key.len() - SHARED_KEY + value.len() + 8;
let old = tx.get(database, &hashed_key);
let old_size = old.map_or(0, |v| v.len());
let mut data = Vec::with_capacity(old_size + size);
data.extend_from_slice(&((key.len() - SHARED_KEY) as u32).to_be_bytes());
data.extend_from_slice(&(value.len() as u32).to_be_bytes());
data.extend_from_slice(&key[SHARED_KEY..]);
data.extend_from_slice(value);
if let Ok(old) = old {
let mut iter = ExtendedValueIter::new(old);
while let Some((k, v)) = iter.next() {

Check failure on line 50 in turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage/extended_key.rs

View workflow job for this annotation

GitHub Actions / rust check / build

this loop could be written as a `for` loop
if k != &key[SHARED_KEY..] {
data.extend_from_slice(&(k.len() as u32).to_be_bytes());
data.extend_from_slice(&(v.len() as u32).to_be_bytes());
data.extend_from_slice(k);
data.extend_from_slice(v);
}
}
};

tx.put(database, &hashed_key, &data, flags)?;
Ok(())
} else {
tx.put(database, &key, &value, flags)
}
}

fn hashed_key(key: &[u8]) -> [u8; MAX_KEY_SIZE] {
let mut result = [0; MAX_KEY_SIZE];
let mut hash = FxHasher::default();
key.hash(&mut hash);
byteorder::BigEndian::write_u64(&mut result, hash.finish());
result[8..].copy_from_slice(&key[0..SHARED_KEY]);
result
}

struct ExtendedValueIter<'a> {
data: &'a [u8],
pos: usize,
}

impl<'a> Iterator for ExtendedValueIter<'a> {
type Item = (&'a [u8], &'a [u8]);

fn next(&mut self) -> Option<Self::Item> {
if self.pos >= self.data.len() {
return None;
}
let key_len = byteorder::BigEndian::read_u32(&self.data[self.pos..]) as usize;
self.pos += 4;
let value_len = byteorder::BigEndian::read_u32(&self.data[self.pos..]) as usize;
self.pos += 4;
let key = &self.data[self.pos..self.pos + key_len];
self.pos += key_len;
let value = &self.data[self.pos..self.pos + value_len];
self.pos += value_len;
Some((key, value))
}
}

impl<'a> ExtendedValueIter<'a> {
fn new(data: &'a [u8]) -> Self {
Self { data, pos: 0 }
}
}
Loading