Giter Club home page Giter Club logo

Comments (11)

NotSqrt avatar NotSqrt commented on June 22, 2024 2

It seems jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]} will be enough !

from jemallocator.

gnzlbg avatar gnzlbg commented on June 22, 2024

How are you using jemallocator ? Typically, the #[global_allocator] is something that can only be meaningfully chosen by the final binary, and when compiling a cdylib, that library should work when linked to multiple different binaries, all using different allocators.

from jemallocator.

NotSqrt avatar NotSqrt commented on June 22, 2024

For the moment, I just put:

#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

in my lib.rs.

Which is enough to switch allocators for cargo test.

from jemallocator.

NotSqrt avatar NotSqrt commented on June 22, 2024

And I build the python extension based on that example : https://github.com/PyO3/rust-numpy/tree/master/examples/simple-extension

from jemallocator.

gnzlbg avatar gnzlbg commented on June 22, 2024

So you probably also need to get the final binary that links to your cdylib to use the same exact version of jemalloc configured in the exact same way. That might be hard to do if the binary that you are using is python which might be using a different allocator.

Hmmm, have you tried generating a staticlib instead of a cdylib ? Pinging: @alexcrichton , they might be able to help or know who else could help. I'm not really sure what happens when you put an allocator in a cdylib - if it gets dynamically linked, it would probably be replaced by the allocator in the final library, and if it gets statically linked, then you can't transfer ownerships of allocations across the cdylib boundary (e.g. you can't allocate memory in the cdylib, and free it in the final binary somewhere else).

from jemallocator.

NotSqrt avatar NotSqrt commented on June 22, 2024

Generating a staticlib instead of a cdylib:

setuptools_rust forces cdylib: https://github.com/PyO3/setuptools-rust/blob/v0.10.6/setuptools_rust/build.py#L142
I changed the code to staticlib, but the lib is not picked up by setuptools_rust, because they specifically look for .so files : https://github.com/PyO3/setuptools-rust/blob/v0.10.6/setuptools_rust/build.py#L226

I'm not sure a static lib will be easy to use as a python extension anyway..

from jemallocator.

NotSqrt avatar NotSqrt commented on June 22, 2024

the final binary that links to your cdylib

Well, setuptools_rust just copies the .so generated by rustc, and from there, the my_lib.so can be used dynamically from python with:

import my_lib

There's no other binary than python itself..

I'll resume working on it on Monday.

from jemallocator.

gnzlbg avatar gnzlbg commented on June 22, 2024

I'm not sure either. Maybe you can try asking in users.rust-lang.org forums ? Other people there might be able to help :)

from jemallocator.

NotSqrt avatar NotSqrt commented on June 22, 2024

Thanks, I'll also ask on the pyo3 repo.

from jemallocator.

NotSqrt avatar NotSqrt commented on June 22, 2024

jemalloc/jemalloc#937 seems related.

from jemallocator.

gnzlbg avatar gnzlbg commented on June 22, 2024

Good find! Glad it works now!

from jemallocator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.